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

spring mvc 事务配置,spring 事务配置说明

2015-12-01 11:05 531 查看
新建项目记录下springmvc和spring的事务配置,解决事务不回滚的问题。
问题说明:
Spring容器优先加载由ServletContextListener(applicationContext.xml)产生的父容器,而SpringMVC(spring-mvc.xml)产生的是子容器。子容器Controller进行扫描装配时装配的@Service注解的实例是没有经过事务加强处理,即没有事务处理能力的Service,而父容器进行初始化的Service是保证事务的增强处理能力的。如果不在子容器中将Service exclude掉,此时得到的将是原样的无事务处理能力的Service。

配置修改:
applicationContext.xml
<!-- 自动扫描dao和service包(自动注入) -->
<!--spring 自动扫描注解的时候,不去扫描@Controller-->
<context:component-scan base-package="com.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>


spring-mvc.xml
<!-- 添加注解驱动 -->
<!--spring mvc 自动扫描注解的时候,不去扫描@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>
参考文章:
/article/3536320.html

http://blog.sina.com.cn/s/blog_5ddc071f0100uf7x.html

http://blog.csdn.net/z69183787/article/details/37819831

http://icanfly.iteye.com/blog/778401

本文出自 “大程熙的小角落” 博客,请务必保留此出处http://dachengxi.blog.51cto.com/4658215/1718423
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: