springmvc+hibernate 注解事务 事务不能提交
2017-03-29 00:00
471 查看
对于用annotation方式的事务注解和bean配置,spring的配置文件 与springMVC的配置文件对包的重复扫描装配会照成失效
在主容器中(applicationContext.xml),将Controller的注解排除掉
<context:component-scan base-package="cn.jr">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
而在springMVC配置文件中将Service注解给去掉
<context:component-scan base-package="cn.jr">
<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是父子容器,所以会产生冲突,由ServletContextListener产生的是父容器,springMVC产生的是子容器,子容器Controller进行扫描装配时装配了@Service注解的实例,而该实例理应由父容器进行初始化以保证事务的增强处理,所以此时得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力。)
在主容器中(applicationContext.xml),将Controller的注解排除掉
<context:component-scan base-package="cn.jr">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
而在springMVC配置文件中将Service注解给去掉
<context:component-scan base-package="cn.jr">
<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是父子容器,所以会产生冲突,由ServletContextListener产生的是父容器,springMVC产生的是子容器,子容器Controller进行扫描装配时装配了@Service注解的实例,而该实例理应由父容器进行初始化以保证事务的增强处理,所以此时得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力。)
相关文章推荐
- 【Spring】spring-mvc hibernate druid jdbc等数据源事务配置详解(解决注解事务不生效问题)
- SpringMVC Spring3 MVC 注解,注释 用@RequestMapping处理请求,多个请求,提交,.do,带参数,url重写
- 项目总结--maven+springsecurity+solr+springmvc+hibernate 延迟加载处理+hibernate sql对象处理(sql执行插入)+spring注解方式+邮件 + JNDI+项目框架写法+jasperreprot的简单应用
- springmvc+spring+hibernate 整合 annotation(全注解)方式
- springmvc+hibernate中几个常用的注解
- atitit.spring hibernate的事务机制 spring不能保存对象的解决
- spring+hibernate xml和注解方式配置事务
- spring mvc+hibernate 实现事务管理(全注解版)
- 被事务代理的spring service 不能使用注解方式发布dubbo服务
- hibernate4 spring3.2 事务不提交分析
- Spring MVC @Transactional注解方式事务失效的解决办法
- springmvc+hibernate整合事务不回滚
- spring+springMVC+Hibernate+spring-data-jpa 完整干净注解版的Demo
- Spring集成Hibernate,使用JPA注解方式,新增数据无法提交
- hibernate+spring 注解 对事务的一些信息 (还没有整理)
- Spring MVC @Transactional注解方式事务失效的解决办法
- Spring MVC @Transactional注解方式事务失效的解决办法
- spring mvc+hibernate 实现事务管理(配置文件版)
- SpringMVC + myBatis + mySQL 全注解 事务配置
- atitit.spring hibernate的事务机制 spring不能保存对象的解决