Spring-IOC annotation scanning

Notes scanned spring in two ways:

  1. 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.

Published 25 original articles · won praise 0 · Views 291

Guess you like

Origin blog.csdn.net/qq_42219004/article/details/105163303