spring事物注意事项

来源:互联网 发布:移动网络转换器 编辑:程序博客网 时间:2024/06/05 20:33

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),否则会造成事物不统一!!!此处一定要注意,也提醒自己!

原创粉丝点击