context:exclude-filter spring事宜【经典-转】

Posted on 2013-12-25 17:12  炫谷  阅读(779)  评论(0编辑  收藏  举报

context:exclude-filter spring事务

如果带上事务,那么用annotation方式的事务注解和bean配置,事务会失效,要将service bean配置到xml文件中才行。

这个问题很经典了
在主容器中(applicationContext.xml),将Controller的注解排除掉
<context:component-scan base-package="com">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

而在springMVC配置文件中将Service注解给去掉
<context:component-scan base-package="com">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>

因为spring的context是父子容器,所以会产生冲突,Controller会先进行扫描装配,而此时的Service还没有进行事务
的增强处理,得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力) ,最后才是
applicationContext.xml中的扫描配置进行事务处理。

 

转自:http://www.myexception.cn/internet/671090.html

Copyright © 2024 炫谷
Powered by .NET 8.0 on Kubernetes