标签:
<context:component-scan base-package="" resource-pattern="**/*.class" name-generator="org.springframework.context.annotation.AnnotationBeanNameGenerator" use-default-filters="true" annotation-config="true"> <context:include-filter type="aspectj" expression=""/> <context:exclude-filter type="regex" expression=""/> </context:component-scan>
默认情况下将自动过滤@Component、@ManagedBean、@Named注解的类并将其注册为Spring管理Bean,可以通过在<context:component-scan>标签中指定自定义过滤器将过滤到匹配条件的类注册为Spring管理Bean,具体定义方式如下:
<context:include-filter type="aspectj" expression=""/> <context:exclude-filter type="regex" expression=""/>
一般情况下没必要进行自定义过滤,如果需要请参考如下示例:
1、cn.javass.spring.chapter12.TestBean14自动注册为Spring管理Bean:
<context:include-filter type="assignable" expression="cn.javass.spring.chapter12.TestBean14"/>
2、把所有注解为org.aspectj.lang.annotation.Aspect自动注册为Spring管理Bean:
<context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
3、将把匹配到正则表达式“cn\.javass\.spring\.chapter12\.TestBean2*”排除,不注册为Spring管理Bean:
<context:exclude-filter type="regex" expression="cn\.javass\.spring\.chapter12\.TestBean2*"/>
4、将把匹配到aspectj表达式“cn.javass.spring.chapter12.TestBean3*”排除,不注册为Spring管理Bean:
<context:exclude-filter type="aspectj" expression="cn.javass.spring.chapter12.TestBean3*"/>
标签:
原文地址:http://www.cnblogs.com/larryzeal/p/5530377.html