spring配置中<context:component-scan/>的use-default-filters的作用

首先来看下spring -context-3.0.xsd中关于<contenxt:component-scan/>属性use-default-filters的定义:

<xsd:attribute name="use-default-filters" type="xsd:boolean"
				default="true">
	<xsd:annotation>
		<xsd:documentation><![CDATA[
	Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service,
	or @Controller should be enabled. Default is "true".
					]]>
		</xsd:documentation>
	</xsd:annotation>
</xsd:attribute>

 即它用来指示是否自动扫描带有@Component、@Repository、@Service和@Controller的类。默认为true,即默认扫描。如果想要过滤其中这四个注解中的一个,比如@Repository,可以添加如下子标签:

<context:component-scan base-package="tv.crm"
    scoped-proxy="targetClass" use-default-filters="true">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>

 而<context:include-filter/>子标签是用来添加扫描注解的。

但是如果添加和排除的是相同,比如:

<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>

 则必须include-filter在前,exclude-filter在后,否则配置不符合spring -context-3.0.xsd要求,Spring容器解析时会出错。上面的配置会把@Repository注解的类排除掉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值