您的位置:首页 > 编程语言 > Java开发

include-filter和exclude-filter

2016-03-07 18:13 531 查看
Spring学习中,遇到问题记录下,与大家分享,如有不对的地方还请多多指教。

<context:include-filter>和<context:exclude-filter>各代表引入和排除的的过滤。


在父容器中(applicationContext.xml)

<context:component-scan base-package="com.coamctech.eastlending">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>


在子容器spring-mvc.xml中

<!-- 自动扫描且只扫描@Controller -->
<context:component-scan base-package="com.coamctech.eastlending" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>


这样配置的原因是因为Spring会用到springmvc.xml 所以就会有父子容器的概念了.applicationcontext.xml是父容器,而springmvc.xml是子容器.在父容器中排除不扫描,在子容器中扫描,这样就避免了冲突。

Controller会进步前辈行扫描装配,而此时的Service还没有进行事务的加强处理,获得的将是原样的Service(没有经过事务加强处理) ,最后才是applicationContext.xml中的扫描设备进行事务处理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring include