Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package

1. Problems encountered in building the springboot framework.

** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

Warning: your application context may not be started because you added comments to the default package. There is also a sentence in the stack information below that includes this meaning.

 
 
1. Reason analysis

I didn’t use @ componentscanning annotation. Why did such an annotation pop up here?

When writing a startup class (the class where the main method is located), springboot does not use @ componentscan to indicate the object scanning range. By default, it scans the objects in the package where the current startup class is located.

(Note: I didn’t add @ componentscan annotation when writing the main method, so he will scan the objects in the package where the application is located)
if the current startup class has no package, an error will be reported when starting: your ApplicationContext is unlikely to start due to a @ componentscan of the default package.

(Note: the application class written in the Java folder does not belong to any package, so the startup class has no package.)

                                        Application is built under other packages

 
2. Solutions

Method 1: build application under other packages

Method 2: add @ componentscan annotation on the application class to specify the package to scan

 

Read More: