Notes scanned spring in two ways:
- Very common one is to use application.xml scan, scanning all the classes below the current package.
<context:component-scan base-package="org.youyuan.bean"></context:component-scan>
2 may be performed by the scan code java code, define a class configuration
@Configuration
@ComponentScan(basePackages = "org.youyuan.service")
public class UserConfig {
}
This configuration corresponds to the class action effect of the above component-scan, which represents the position of the scanning basePackages @ComponentScan the packet.
Of course, there is another way to scan the surface, by scanning the annotation.
@Configuration
@ComponentScan(basePackages = "org.youyuan.service",useDefaultFilters = true,excludeFilters =
{@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = Controller.class)})
public class UserConfig {
}
All under a scanning Bean org.youyuan.service Currently, in addition to Controller.