1.spring事物失效
很有可能是spring和springmvc配置文件中的包扫描配置冲突,注意是不是按照以下方式配置
spring配置文件,将Controller注解排除扫描
<context:component-scan base-package="com.mine">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
springmvc配置文件,只扫描Controller注解
<context:component-scan base-package="com.mine" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>2.sqlsession频繁创建,导致spring事物不统一
不论spring与hibernate还是mybatis整合,如果想开启事物一定要是Controller调用Service里的第一个方法就开启事物,设置@Transaction(readonly = false),否则会造成事物不统一!!!此处一定要注意,也提醒自己!
本文探讨了Spring事务管理中可能出现的问题,如事务失效的原因及解决方案,特别关注了spring与springmvc配置文件中包扫描配置冲突的问题。此外,还讨论了如何确保SQLSession在整合时能够统一事务管理。
1718

被折叠的 条评论
为什么被折叠?



