1.声名式的配置事务的方法
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
2.注解式的事
方法上加上注解
@Transactional(rollbackFor = RuntimeException.class,propagation = Propagation.REQUIRED)
try{
returnVal = dao.save(model);
}catch (Exception e){
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
return returnVal;
注意点 如果在Controller使用注解,必须在DispatcheServlet 上下文使用注解配置,因为在sprigmvc加载的过程中会先加载ContextLoaderListener上下文;