Spring

How to configure JPA with JPQL in Spring Boot Application - “can't resolve symbol..”

南笙酒味 提交于 2021-02-08 08:22:25
问题 I have a dependency spring-boot-starter-data-jpa Configuration for JPA is inside application.properties : spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC spring.datasource.username=name spring.datasource.password=pass ... When I create @Entity: @Entity @Table(name="cats") public class Cat { @Column(name="age") private int age; .... } It works well. When i try to use JPQL : "select cat from Cat cat" Intellij idea emphasizes it and says "Can't resolve symbol Cat" , I

How to configure JPA with JPQL in Spring Boot Application - “can't resolve symbol..”

旧时模样 提交于 2021-02-08 08:21:54
问题 I have a dependency spring-boot-starter-data-jpa Configuration for JPA is inside application.properties : spring.datasource.url=jdbc:mysql://localhost:3306/db?serverTimezone=UTC spring.datasource.username=name spring.datasource.password=pass ... When I create @Entity: @Entity @Table(name="cats") public class Cat { @Column(name="age") private int age; .... } It works well. When i try to use JPQL : "select cat from Cat cat" Intellij idea emphasizes it and says "Can't resolve symbol Cat" , I

What is the alternative of using Qualifier annotation in XML in Spring?

拈花ヽ惹草 提交于 2021-02-08 08:17:11
问题 In Spring , if there are two bean ids which refer to the same class and we just want to inject values from only one bean, then we normally use the following annotations in conjunction : @Autowired @Qualifier("bean1") How to achieve the same thing using the xml specification ? What is the alternative of using qualifier annotation in xml ? 回答1: Not an exact alternative but you can use autowire-candidate="false" to all those beans which you want to exclude from being autowired apart from the one

how to resolve Spring boot @EnableAsync and @Async problem?

試著忘記壹切 提交于 2021-02-08 08:15:14
问题 my service: @Service public class ForgetService{ @Async public CompletableFuture<Object> getTokenService() { Map<String, Object> map = new HashMap<>(8); map.put("status", ErrorEnum.TOKEN_SUSSCESS.getStatus()); map.put("message", ErrorEnum.TOKEN_SUSSCESS.getMessage()); return CompletableFuture.completedFuture(map); } } my controller: @RestController public class ForgetController { private final ForgetService forgetService; @Autowired private ForgetController(ForgetService forgetService) { this

What is the alternative of using Qualifier annotation in XML in Spring?

有些话、适合烂在心里 提交于 2021-02-08 08:14:12
问题 In Spring , if there are two bean ids which refer to the same class and we just want to inject values from only one bean, then we normally use the following annotations in conjunction : @Autowired @Qualifier("bean1") How to achieve the same thing using the xml specification ? What is the alternative of using qualifier annotation in xml ? 回答1: Not an exact alternative but you can use autowire-candidate="false" to all those beans which you want to exclude from being autowired apart from the one

how to resolve Spring boot @EnableAsync and @Async problem?

风流意气都作罢 提交于 2021-02-08 08:14:11
问题 my service: @Service public class ForgetService{ @Async public CompletableFuture<Object> getTokenService() { Map<String, Object> map = new HashMap<>(8); map.put("status", ErrorEnum.TOKEN_SUSSCESS.getStatus()); map.put("message", ErrorEnum.TOKEN_SUSSCESS.getMessage()); return CompletableFuture.completedFuture(map); } } my controller: @RestController public class ForgetController { private final ForgetService forgetService; @Autowired private ForgetController(ForgetService forgetService) { this

Spring Thymeleaf send object from select option

南楼画角 提交于 2021-02-08 08:12:11
问题 I have a problem with sending an object with values from inputs fields to controller in add user method. It generates an error ("Bad request") caused by a select box. Tables connection works well, I can print a list of users and add user window, but adding a user is not working. Code: Entity class fragment (further are getters and setters with hibernate annotations) @Entity @Table(name = "user_emes") public class UserEmes implements java.io.Serializable { private long idUser; private String

Parallel step execution of ItemStreamReader in SpringBatch

江枫思渺然 提交于 2021-02-08 07:42:35
问题 I have a ItemStreamReader ( extends AbstractItemCountingItemStreamItemReader ), the reader on its own is quite fast, but the the following processing takes quite some time. From a business point of view I can process as many items in parallel as I want. As my ItemStreamReader is reading a large JSON file with a JsonParser, it ends up to be statefull. So just adding a TaskExecutor to the Step does not work and throws parsing exceptions and the following log output by spring batch: 16:51:41.023

Spring ResponseEntity and forward

为君一笑 提交于 2021-02-08 07:40:49
问题 Im a SpringBoot application have a REST controller that handles several cases and one of these cases it must forward to another controller. @PutMapping( value = "/rest/endpoint", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity<CustomObject> doPut(@RequestBody myDataToBeHandled) { if(caseAHolds(myDataToBeHandled){ return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST); } else if(caseBHolds(myDataToBeHandled){

Springboot国际化信息(i18n)解析

别来无恙 提交于 2021-02-08 07:37:56
国际化信息理解 国际化信息也称为本地化信息 。 Java 通过 java.util.Locale 类来表示本地化对象,它通过 “语言类型” 和 “国家/地区” 来创建一个确定的本地化对象 。举个例子吧,比如在发送一个具体的请求的时候,在header中设置一个键值对:"Accept-Language":"zh",通过Accept-Language对应值,服务器就可以决定使用哪一个区域的语言,找到相应的资源文件,格式化处理,然后返回给客户端。 MessageSource Spring 定义了 MessageSource 接口,用于访问国际化信息。 getMessage(String code, Object[] args, String defaultMessage, Locale locale) getMessage(String code, Object[] args, Locale locale) getMessage(MessageSourceResolvable resolvable, Locale locale) MessageSourceAutoConfiguration springboot提供了国际化信息自动配置类,配置类中注册了ResourceBundleMessageSource实现类。 1 @Configuration 2