cause : When a colleague writes a demo, The Bean has a @component and cannot be scanned by spring (the idea will not be able to get the corresponding bean at compile time).
Later, the research was related to the location of the document package.
Springboot Bean Assembly Rules:
Scan from top to bottom according to the package location where the application class is located!
"Application class" refers to the project entry class for Springboot. The location of this class is critical:
If the package for the application class is: Then the location of the io.github.gefangshuai.app
scan is: The io.github.gefangshuai.app
package and all of its sub-packages. If the bean that needs to be injected is not io.github.gefangshuai.app
under the package and its child package, it will not be scanned.
Note: You can specify a scanned package by adding @componentscan (basepackages={"xxx.xxx", "xxx.xxx"}) to the application class, but the package will not be scanned under the application class by default once it is specified.
about issues that springboot beans cannot inject (related to package location) Change the automatically scanned package