Spring include-filter和exclude-filter

<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中的扫描设备进行事务处理。

 

猜你喜欢

转载自blog.csdn.net/rogerxue12345/article/details/83186513
今日推荐