My goal is to port the Spring boot application previously developed with Spring Boot 1.3 to the newest version of Spring to download version 1.4. An application consists of several maven modules, and only one of them contains a class annotated with @SpringBootApplication.
One part of the migration is to use annotations @WebMvcTestto effectively test controllers, and this is where the problem arises.
Consider the application from the Spring github download page. @WebMvcTestthe annotation works fine because, as far as I understand (after several tests), the main package is annotated @SpringBootApplication. Please note that I adhere to the same concept as in the example above for my own tests @WebMvcTest.
The only difference that I see in my application is that the controller classes are located in a separate maven module (without @SpringBootApplicationan annotated class), but with @Configuration and configurations SpringBootConfiguration. If I do not comment on any class with @SpringBootApplication, I always get approval while testing the controller. My contention is the same as when SampleTestApplication class in the above example is modified to have only @EnableAutoConfigurationand @SpringBootConfigurationannotations ( @SpringBootApplicationno):
getVehicleWhenRequestingTextShouldReturnMakeAndModel(sample.test.web.UserVehicleControllerTests) Time elapsed: 0.013 sec <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<404>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:54)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:81)
at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:664)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:171)
at sample.test.web.UserVehicleControllerTests.getVehicleWhenRequestingTextShouldReturnMakeAndModel(UserVehicleControllerTests.java:68)
? , @SpringBootApplication, @WebMvcTest?
EDIT 1: maven . . NoSuchBeanDefinitionException , . "" @SpringBootApplication - .
2: EDIT 1, . @ComponentScan , , beans . , @Controller bean ( @WebMvcTest (... class)) @WebMvcTest.
EDIT 3: Spring issue.