definition
@ComponentScan: class default scan @SpringBootApplication located at the same level package
effect
-
When the startup and controller in the same package, this time to access to the corresponding request address,
-
When the package is higher than the starting class is where the packet controller, this time can access the request address.
For example: In the class start com.sdbairui
above where the packet controller, it is possible to request access to the corresponding address. -
When starting and controller classes in a directory is not in the same sweep plane can not automatically control such as starting class: com.sdbairui.test, the controller com.sdbairui.controller, in which case the controller can not be scanned.
Solution:
The added annotations on startup class:
@ComponentScan(basePackages= {"com.sdbairui.controller"})
wherein basePackages value is an array, a plurality of strings can be specified package, this time can be scanned.
If a plurality of packages may be scanned:
@ComponentScan(basePackages= {"com.sdbairui.controller,com.sdbairui.test"})