代码如下:
applicationContext-mybatis.xml
<bean id="sSF" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:com/telchina/**/*.xml"></property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.telchina"></property>
<property name="sqlSessionFactoryBeanName" value="sSF"></property>
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 拦截器方式配置事务 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.RuntimeException"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactionPointcut" expression="execution(* com.telchina.app.service.impl.*Impl.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut" advice-ref="transactionAdvice" />
</aop:config>
@Service("demoService")
public class DemoServiceImpl implements DemoService {
@SuppressWarnings("rawtypes")
@Override
public String rollbackTest(List demoList) {
// TODO Auto-generated method stub
Iterator itr = demoList.iterator();
while (itr.hasNext()) {
Map demoMap = (Map) itr.next();
demoMapper.updateDemo(demoMap);
throw new RuntimeException("rollbackTest");
}
return "";
}
}
List中传入了两个对象,总是能更新一个,事务不回滚,愁死了,求各位大侠指点!!!!