spring结合spring mvc下用注解式事务不生效
来源:互联网 发布:淘宝热卖场女装 编辑:程序博客网 时间:2024/05/12 23:10
项目开发过程中遇到spring注解事务不生效的情况,项目使用的是spring mvc、spring、mybatis 。bean都是用spring的注解管理的,事务也是用的注解式。经过几番折腾发现问题,特此记录解决方法如下:
一、在applicationContext.xml文件中扫描bean时排除Controller。
<context:component-scan base-package="com.newmode.fcm"><context:include-filter type="annotation" expression="org.springframework.stereotype.Service"/><context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/></context:component-scan>
二、在springMvc.xml文件中扫描Controller时排除Service。
<context:component-scan base-package="com.newmode.fcm.web"><context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/><context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/></context:component-scan>
运行,nice,完美控制,原因如下:
因为spring是由org.springframework.web.context.ContextLoaderListener加载,spring mvc是由org.springframework.web.servlet.DispatcherServlet加载,互不干扰,如果spring mvc中不排除@Service他就会一并把@Service扫描装配进来,而该@Service理应由父容器进行初始化以保证事务的一致性,故这里要进行如上处理。
0 0
- spring结合spring mvc下用注解式事务不生效
- spring mvc 注解事务不生效
- spring事务注解不生效
- spring mvc 事务不生效 不回滚
- spring mvc 事务不生效 不回滚
- spring mvc 注解配置StringHttpMessageConverter不生效
- spring mvc 注解配置StringHttpMessageConverter不生效
- spring mvc 注解配置StringHttpMessageConverter不生效
- 【Spring】spring-mvc hibernate druid jdbc等数据源事务配置详解(解决注解事务不生效问题)
- spring mvc @Transaction注解不生效的解决
- spring mvc事务注解
- spring 注解aop不生效
- Spring @Transactional注解不生效
- Spring声明式事务注意点,以及不生效情况
- Spring事务不生效的解决过程
- Spring事务不生效问题汇总
- spring事务 方法调用内部方法 事务不生效
- Spring mvc 注解总结 (下)
- 如何在编译的时候,控制删除apk不用的资源?
- Hadoop的调度器
- 据说这次是下了血本弄得、不知道是真假哇~
- byte[]数组和int之间的转换
- 《失控》读书笔记
- spring结合spring mvc下用注解式事务不生效
- select a specific column from a ref cursor
- Javascript的执行过程详细研究
- 【问题汇总】图片资源引起IllegalArgumentException异常的问题
- Cocos2dx 3.0rc0 漂亮的 数字、英文显示
- Eclipse检出svn项目之后无法识别为java项目解决办法
- 如何在fastboot 里面添加新的命令
- Could not find or load main class org.apache.hadoop.util.VersionInfo
- Spring Security3边学边写(N)会话管理和并行控制