Some uses of [spring] based on the annotation @ComponentScan

The use of ComponentScan based on xml form is generally as follows

<context:component-scan base-package="com.luna" use-default-filters="false">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

Based on the use of annotation @ComponentScan

@Configuration
@ComponentScan(value = "com.luna", excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value ={com.luna.service.PersonService.class} )
})
public class ScanConfig {
}

 

@ComponentScan some common parameters

//Basic attribute value/basePackages: Specify a set of packages to scan, and the files under these packages and their subpackages will be scanned. (The default base package is the package where the configuration class is located)

classes: Directly specify some classes to be scanned, and the packages where these classes are located and their subpackages will also be scanned.

nameGenerator: Specify a default scanning component named class, the default name uses the first letter of the component class name in lowercase.

excludeFilters: A set of @ComponentScan .Filter annotation configurations are required, each @Filter can be configured with a set of filtering rules, and multiple @Filters can be configured with different filtering rules based on regular/annotation/specific classes.

includeFilters: the opposite.

 

FilterType.ANNOTATION (default) A set of annotations that hits all classes that use the annotation, {MyAnno.class} -
FilterType.ASSIGNABLE_TYPE a set of concrete classes -
FilterType.ASPECTJ - A set of expressions that hit classes using Aspectj expressions
FilterType.REGEX - A set of expressions, using the regular hit class
FilterType.CUSTOM Custom TypeFilter. -

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324613806&siteId=291194637