Spring

Spring: unit test for class that has both field & constructor injection

好久不见. 提交于 2021-02-19 02:46:05
问题 I have below setup of classes. class Base { @Autowired private BaseService service; //No getters & setters .... } @Component class Child extends Base { private final SomeOtherService otherService; @Autowired Child(SomeOtherService otherService) { this.otherService = otherService; } } I am writing a unit test for the Child class. If I use @InjectMocks then the otherService comes out to be null. If I use, the constructor of Child class in the setup of the test, then the fields in Base class

No mapping found for HTTP request with URI [] in DispatcherServlet with name ' [duplicate]

人盡茶涼 提交于 2021-02-19 01:16:31
问题 This question already has answers here : Why does Spring MVC respond with a 404 and report “No mapping found for HTTP request with URI […] in DispatcherServlet”? (11 answers) Closed 4 years ago . Morning, I already checked most of the answers to this problem (No mapping found for HTTP request with URI.... in DispatcherServlet with name) and also (No mapping found for HTTP request with URI [/ChickenTest/index] in DispatcherServlet with name 'dispatcherServlet') but I'm still getting "No

Is there a way to integrate java bean validation api With Spring RestTemplate

≡放荡痞女 提交于 2021-02-19 01:15:56
问题 Is there a way to integrate spring RestTemplate with JavaBean validation api. ? I know there is a integration for spring controller. you can put @Valid on request body param and if Employee is not valid you will get MethodArgumentNotValidException exception . which you can handel in exception handler class. @PostMapping(value = "/add", produces = APPLICATION_JSON_VALUE) public ResponseEntity<String> addEmployee( @RequestBody @Valid Employee emp) { //... } But what I want is similar way to

Is there a way to integrate java bean validation api With Spring RestTemplate

╄→尐↘猪︶ㄣ 提交于 2021-02-19 01:08:50
问题 Is there a way to integrate spring RestTemplate with JavaBean validation api. ? I know there is a integration for spring controller. you can put @Valid on request body param and if Employee is not valid you will get MethodArgumentNotValidException exception . which you can handel in exception handler class. @PostMapping(value = "/add", produces = APPLICATION_JSON_VALUE) public ResponseEntity<String> addEmployee( @RequestBody @Valid Employee emp) { //... } But what I want is similar way to

Is there a way to integrate java bean validation api With Spring RestTemplate

旧巷老猫 提交于 2021-02-19 01:07:25
问题 Is there a way to integrate spring RestTemplate with JavaBean validation api. ? I know there is a integration for spring controller. you can put @Valid on request body param and if Employee is not valid you will get MethodArgumentNotValidException exception . which you can handel in exception handler class. @PostMapping(value = "/add", produces = APPLICATION_JSON_VALUE) public ResponseEntity<String> addEmployee( @RequestBody @Valid Employee emp) { //... } But what I want is similar way to

How to filter postgres array column with the JPA criteria API?

大憨熊 提交于 2021-02-18 23:01:48
问题 I am using: Hibernate 4.3.5 Spring JPA 1.6.0 Javax Persistence API 2.1 The "refcodemailing" column is defined as an array of int: int[] My entity object: @Entity @Table public class CalendarEvent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id = 0; @Convert(converter = IntegerArrayConverter.class) @Column(name = "refcodemailing") private final List<Integer> mailingCodes = new ArrayList<>(); // .... } I am trying to filter the column array with the

Why does Spring Boot discover but not instantiate a @Component?

本秂侑毒 提交于 2021-02-18 22:55:55
问题 I have a Spring Boot application with the following structure com.package Application - annotated with @SpringBootApplication Configuration - annotated with @Configuration Component1 - annotated with @Component, constructor annotated with @Autowired com.package.subpackage Component2 - annotated with @Component, constructor annotated with @Autowired My application class is package com.package; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

Why does Spring Boot discover but not instantiate a @Component?

蓝咒 提交于 2021-02-18 22:55:36
问题 I have a Spring Boot application with the following structure com.package Application - annotated with @SpringBootApplication Configuration - annotated with @Configuration Component1 - annotated with @Component, constructor annotated with @Autowired com.package.subpackage Component2 - annotated with @Component, constructor annotated with @Autowired My application class is package com.package; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure

How can I start spring boot application in docker with profile?

旧时模样 提交于 2021-02-18 22:43:31
问题 I have a simple spring-boot project: -resources -application.yaml -application-test.yaml And I have this Dockerfile : FROM openjdk:8-jdk-alpine EXPOSE 8080 ADD micro-boot.jar micro-boot.jar ENTRYPOINT ["java","-Dspring.profiles.active=test" "-jar","/micro-boot.jar"] 1) I build image - C:\micro-boot>docker build -f Dockerfile -t micro-boot . 2) show all images - C:\micro-boot>docker image ls -a micro-boot latest ccc9a75ebc24 4 seconds ago 112MB 3) try to start C:\micro-boot>docker image ls -a

How to configure CommonsPool2TargetSource in spring?

我只是一个虾纸丫 提交于 2021-02-18 22:20:05
问题 This become pain in my neck!!! I have three queries. 1)I want to configure CommonsPool2TargetSource in my project for pooling of my custom POJO class. What I have done so far : MySpringBeanConfig class : @Configuration @EnableWebMvc @ComponentScan(basePackages = {"com.redirect.controller","com.redirect.business","com.redirect.dao.impl","com.redirect.model"}) @EnableTransactionManagement @PropertySource("classpath:" + JioTUConstant.SYSTEM_PROPERTY_FILE_NAME + ".properties") @Import(