springmvc-servlet.xml中use-default-filters的作用

1、<!-- 启用注解扫描,并定义组件查找规则 ,mvc层只负责扫描@Controller -->

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


2、在context:component-scan可以添加use-default-filters,spring配置中的use-default-filters用来指示是否自动扫描带有@Component@Repository@Service@Controller的类。默认为true,即默认扫描。


3、如果想要过滤其中这四个注解中的一个,比如@Repository,可以添加<context:exclude-filter />子标签:

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

</pre><p></p><pre>

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

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

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

<span style="font-size:18px;"><context:component-scan base-package="tv.crm" scoped-proxy="targetClass" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan></span>






  • 7
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值