[JAVA] Spring boot Things that beginners tend to have (@ComponentScan)

Event

The controller class @RequestMapping stopped working and the screen disappeared. Occurs when refactoring the package configuration.

Cause

I changed the package configuration without knowing much about @ComponentScan running on @SpringBootApplication.

Commentary

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 ・ ・ ・

Correspondence

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

Spring boot Things that beginners tend to have (@ComponentScan)
[Spring Boot] How to create a project (for beginners)
Try Spring Boot from 0 to 100.
Introduction to Spring Boot ① ~ DI ~
Introduction to Spring Boot ② ~ AOP ~
Introduction to Spring Boot Part 1
I have summarized the articles that programming beginners referred to.
8 things to insert into DB using Spring Boot and JPA
A solution to Docker errors that beginners tend to get stuck in
How to set Spring Boot + PostgreSQL
How to use ModelMapper (Spring boot)
Upgrade spring boot from 1.5 series to 2.0 series
A memo that touched Spring Boot
[Rails] The 12 functions that beginners have added to the problem-solving portfolio are these!
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
[Introduction to Spring Boot] Form validation check
Story when moving from Spring Boot 1.5 to 2.1
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
How to split Spring Boot message file
Add spring boot and gradle to eclipse
Book introduction: Spring Boot Recommended reference book for beginners!
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
How to use built-in h2db with spring boot
How to make Spring Boot Docker Image smaller
How to use Spring Boot session attributes (@SessionAttributes)
The story of raising Spring Boot 1.5 series to 2.1 series
Try to implement login function with Spring Boot
How to add a classpath in Spring Boot
An introduction to Spring Boot + in-memory data grid
How to bind to property file in Spring Boot
Tasks that tend to be given to fledgling engineers
Try to automate migration with Spring Boot Flyway
[Java] Article to add validation with Spring Boot 2.3.1.
I wanted to gradle spring boot with multi-project
Apply Twitter Bootstrap 4 to Spring Boot 2 using Webjars
[Spring Boot] How to refer to the property file
[Introduction to Spring Boot] Authentication function with Spring Security
Spring Boot --How to set session timeout time
From building an AWS cloud environment to deploying a Spring Boot app (for beginners)
A memo that I was addicted to when making batch processing with Spring Boot
A site that was easy to understand when I was a beginner when I started learning Spring Boot
A story that stumbled when deploying a web application created with Spring Boot to EC2