首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

include-filter跟exclude-filter

2013-03-10 
include-filter和exclude-filter最近仔细看看项目中的代码,发现一直在做项目,就是想着怎么去实现,剩下的东

include-filter和exclude-filter
  最近仔细看看项目中的代码,发现一直在做项目,就是想着怎么去实现,剩下的东西基本都没注意看。结果到面试的时候我才发现这会是一件很悲剧的事情。所以痛定思痛,回过头来看看细节,只要现在开始,还不算晚.
 

<context:include-filter>和<context:exclude-filter>各代表引入和排除的過濾
 
  在主容器中(applicationContext.xml),看到
 
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --><context:component-scan base-package="cn.tonyan.tonyan.web" ><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>
 
  很是奇怪为什么会是 exclude. 然后在(spring-mvc.xml),看到
<!-- 自动扫描且只扫描@Controller --><context:component-scan base-package="cn.tonyan.tonyan.web" use-default-filters="false"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>


  那为什么会是这样配置呢?
  原来因为会用到springmvc.xml 所以就会有父子容器的概念了.
  applicationcontext.xml是父容器,而springmvc.xml是子容器.
  在父容器中排除不扫描,在子容器中扫描,这样就避免了冲突.
 
  引用 因为spring的context是父子容器,所以会产生冲突,Controller会进步前辈行扫描装配,而此时的Service还没有进行事务的加强处理惩罚,获得的将是原样的Service(没有经过事务加强处理惩罚,故而没有事务处理惩罚才能) ,最后才是applicationContext.xml中的扫描设备进行事务处理惩罚 

热点排行