Home > Java > javaTutorial > body text

How to solve the problem that SpringBoot cannot scan the Controller

WBOY
Release: 2023-05-14 08:10:17
forward
6370 people have browsed it

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
Copy after login
2, the second

@SpringBootApplication      
@ComponentScan
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template