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
spring-mvc.xml
/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
问题说明:
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
相关文章推荐
- Spring事务管理的三种方式
- Java基础01 从HelloWorld到面向对象
- spring中注解的实现原理
- SpringMVC 拦截器实现原理和登录实现
- springMVC重定向
- Java streamtool
- Eclipse Rap开发 异步刷新UI处理
- Java图形化界面设计——布局管理器之null布局(空布局)
- Java图形化界面设计——布局管理器之CardLayout(卡片布局)
- Java图形化界面设计——布局管理器之GridLayout(网格布局)
- Java图形化界面设计——布局管理器之BorderLayout(边界布局)
- Java图形化界面设计——布局管理器之FlowLayout(流式布局)
- Java图形化界面设计——中间容器(Jpanel)
- Java图形化界面设计——容器(JFrame)
- 搭建springMVC+Mybatis的Maven项目过程中遇到的问题汇总。
- Java快速教程
- java集合框架总结
- javadoc 警告:编码 GBK 的不可映射字符
- spring源码剖析(四)自定义标签解析流程
- Android Studio启动时卡在Fetching Android SDK 以及导入Eclipse工程慢的解决方法