【SpringMVC】<context:include-filter>和<context:exclude-filter>

本文介绍了如何通过配置ApplicationContext.xml和spring-mvc.xml实现组件扫描,分别管理业务逻辑和控制器组件。通过&lt;context:component-scan&gt;标签指定包路径,并使用&lt;context:exclude-filter&gt;排除特定类型的类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ApplicationContext.xml和spring-mvc.xml分开配置,各司其职。


在ApplicationContext.xml中配置:

<context:component-scan base-package="com.practise">
	<context:exclude-filter type="regex" expression="com.practise.controller"/>
</context:component-scan>

如果配置了<context:component-scan>那么<context:annotation-config/>标签就可以不用再xml中配置了,因为前者包含了后者。

其中,<context:exclude-filter>的type可以为下面的值:

</pre></p><p>annotatioin: 标识了某个annotation的类。例如,<span style="background-color: rgb(240, 240, 240);"><context:exclude-filter type="regex" expression="</span><span style="color: rgb(0, 0, 255);">org.springframework.stereotype.Controller</span><span style="background-color: rgb(240, 240, 240);">"/>.</span></p><p>regre: 匹配类全名的正则表达式。</p><p>assignable:a class (or interface) that the  target components are assignable to (extend/implement)。</p><p>assignable:an AspectJ type pattern expression to be matched by the target components。</p><p>assignable:a custom implementation of the org.springframework.core.type.TypeFilter interface。</p><p></p><p>在spring-mvc.xml中配置:</p><p><pre name="code" class="html"><context:component-scan base-package="com.practise.controller" />

同时,也可以将properties的配置文件分开配置。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值