spring配置事务不起作用解决

来源:互联网 发布:淘宝发展前景怎么样 编辑:程序博客网 时间:2024/05/16 17:36

在项目中配置spring 的事务时发现没有起作用,使用注解和配置的方式都不行,后来发现是spring的子容器先于父容器启动,造成在controller中注入service时还没有加载事务;

解决方案:在applicationContext.xml中添加

<context:component-scan base-package="com.gm.yanshang.yanshang_project" >
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

mvc的配置文件只扫描controller包就好,不用扫描所有包或配置为

 <context:component-scanbase-package="com.gm.yanshang.yanshang_project">

           <context:include-filter type="annotation"expression="org.springframework.stereotype.Controller" />

           <context:exclude-filter type="annotation"expression="org.springframework.stereotype.Service" />

        </context:component-scan>



其他可能造成此问题的原因:

1:mysql的引擎是否是InnoDB引擎只有InnoDB支持事务

2:事务配置的切面等是否正确

原创粉丝点击