The controller class @RequestMapping stopped working and the screen disappeared. Occurs when refactoring the package configuration.
I changed the package configuration without knowing much about @ComponentScan running on @SpringBootApplication.
The annotations executed by @SpringBootApplication are as follows. @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class), @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
Of the above, @ComponentScan scans the class annotated with @Component and DIs it for use. (The @Controller added to the controller includes @Component.) @ComponentScan scans the packages of the class with @ComponentScan and the packages under it. This time, when refactoring the controller group, @ComponentScan was moved to the existing package in parallel.
▼com.example ▼application ▼Application.java ▼controller ▼IndexController.java ・ ・ ・ ▼entity ・ ・ ・
Refactor the package configuration so that the Application class with @ComponentScan comes to the top.
▼com.example ▼Application.java ▼component ▼controller ▼IndexController.java ・ ・ ・ ▼entity ・ ・ ・
Recommended Posts