Home  >  Article  >  Java  >  How to solve the problem that SpringBoot cannot scan the Controller

How to solve the problem that SpringBoot cannot scan the Controller

WBOY
WBOYforward
2023-05-14 08:10:176174browse

SpringBoot novice creates a project, but the Controller cannot be scanned and a series of problems

1.

How to solve the problem that SpringBoot cannot scan the Controller

2.

How to solve the problem that SpringBoot cannot scan the Controller

3.

How to solve the problem that SpringBoot cannot scan the Controller

4.

How to solve the problem that SpringBoot cannot scan the Controller

##5.

How to solve the problem that SpringBoot cannot scan the Controller

6. Another way is to start the service class and add @ComponentScan(basePackages={"xxx.xxx.xx", "xxx.xxx.xx"}) which contains the package Fully qualified name, can be multiple

SpringBoot The custom controller cannot be scanned to

SpringBoot. The custom controller route cannot be found because the startup class and the custom Controller package are not in the same directory. Down.

Officially recommended location for application.java: Place other beans in the same package path as application.java, but this is not recommended.

How to solve the problem that SpringBoot cannot scan the Controller

Solution:

1. Place the self-built controller class in the same directory as the startup class (this is not recommended).

2. Change the @RestController @EnableAutoConfiguration annotation of the startup class to @SpringBootApplication.

3. Start the class @RestController @EnableAutoConfiguration annotation plus @ComponentScan annotation.

Two annotation configuration methods using springboot scanning:

1, the first

@Controller 
@EnableAutoConfiguration 
@ComponentScan
2, the second

@SpringBootApplication      
@ComponentScan

The above is the detailed content of How to solve the problem that SpringBoot cannot scan the Controller. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete