spring+mybatis 注解事务失效

@Transactional可用要保证:
1必须是父容器加载的
2标注的方法是public
3默认回滚是runtimeException。可通过   @Transactional(rollbackFor={ArithmeticException.class})    修改

对于第一点说明:
web.xml加载顺序是context-param -> listener-> filter -> servlet
listener加载config是父容器,有@Transactional方法的类必须是在父容器加载,
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-config.xml</param-value>
</context-param>
=============
而如何放在
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
  放在spring mvc config里加载的确不可以。
==============
另外<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 
中自动提交可以不配置也可以回滚  

         <property name="autoCommitOnClose" >
         <value>false</value>
         </property>

你可能感兴趣的:(spring)