小弟,现在正在做一个项目。现在遇到问题。。
spring mvc + mybatis 事务不回滚配置文件如下
web.xml
<!-- 配置文件位置,默认为/WEB-INF/applicationContext.xml -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/applicationContext.xml</param-value>
</context-param> <!-- 上下文Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- servlet控制跳转 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置文件 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config/context-dispatcher.xml</param-value>
</init-param>
</servlet>
applicationContext.xml<!-- 创建SqlSessionFactory,同时指定数据源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean> <!-- 可通过注解控制事务 -->
<tx:annotation-driven />

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- spring declarative transaction management -->
<aop:config>
<aop:pointcut id="fooServiceMethods" expression="execution(* com.service.impl.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
     
context-dispatcher.xml
<context:component-scan base-package="com.*">
       
  </context:component-scan>
java 代码如下
@Transactional(rollbackFor=Exception.class)
public void workAddDefault() throws Exception{    User user = new User();
user.setId(99);
user.setName("9981");
user.setPassword("9981");

    
iDao.addDefault(super.getSqlMap(user));

user.setId(99);
user.setName("99999999999999999999999999999998");
user.setPassword("998");

    
iDao.addDefault(super.getSqlMap(user));
throw new RuntimeException();

}但是,现在就是不回滚求大家帮忙看看~~~