国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

java - spring事務(wù)不回滾

瀏覽:143日期:2023-12-01 09:40:22

問題描述

1.spring事務(wù)不會回滾,網(wǎng)上的方法都試過了,沒有效果。2.配置如下:

1.spring.xml:

<context:component-scan base-package='com.szcshl'><context:exclude-filter type='annotation' expression='org.springframework.stereotype.Controller'/> </context:component-scan>2.springmvc.xml

<context:component-scan base-package='com.szcshl' use-default-filters='false'><context:include-filter type='annotation' expression='org.springframework.stereotype.Controller'/> </context:component-scan>3.spring-hibernate.xml

<!-- 配置事務(wù)管理器 --> <bean name='transactionManager' class='org.springframework.orm.hibernate4.HibernateTransactionManager'><property name='sessionFactory' ref='sessionFactory'></property> </bean> <!-- 注解方式配置事物 --> <!-- <tx:annotation-driven transaction-manager='transactionManager' /> --> <!-- 攔截器方式配置事物 --> <tx:advice transaction-manager='transactionManager'><tx:attributes> <tx:method name='add*' /> <tx:method name='save*' /> <tx:method name='update*' /> <tx:method name='modify*' /> <tx:method name='edit*' /> <tx:method name='delete*' /> <tx:method name='remove*' /> <tx:method name='repair' /> <tx:method name='deleteAndRepair' /> <tx:method name='get*' propagation='SUPPORTS' read-only='true' /> <tx:method name='find*' propagation='SUPPORTS' read-only='true' /> <tx:method name='load*' propagation='SUPPORTS' read-only='true' /> <tx:method name='search*' propagation='SUPPORTS' read-only='true' /> <tx:method name='datagrid*' propagation='SUPPORTS' read-only='true' /> <tx:method name='*' propagation='SUPPORTS' read-only='true' /></tx:attributes> </tx:advice> <aop:config><aop:pointcut expression='execution(* com.szcshl.service..*Impl.*(..))' /><aop:advisor pointcut-ref='transactionPointcut' advice-ref='transactionAdvice' /> </aop:config>4.controller

@RequestMapping(value = '/Save' , method= RequestMethod.POST) public void departmentSave(Department department, HttpServletResponse response){ departmentService.save(department); throw new RuntimeException('拋出異常'); }5.service

@Service@Transactionalpublic class DepartmentServiceImpl extends BaseServiceImpl<Department> implements DepartmentService {@Autowired private DepartmentDao deptDao; ...... public void save(Department entity) {deptDao.save(entity); }}6.baseDao

public class BaseDaoImpl<T> implements BaseDao<T> { private SessionFactory sessionFactory; protected Class<T> entityClass; public SessionFactory getSessionFactory() {return sessionFactory; } @Resource public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory; } public Session getCurrentSession() {return this.sessionFactory.getCurrentSession(); } @SuppressWarnings('rawtypes') protected Class getEntityClass() {if (entityClass == null) { entityClass = (Class<T>) ((ParameterizedType) getClass() .getGenericSuperclass()).getActualTypeArguments()[0];}return entityClass; } @Transactional public Serializable save(T entity) {return this.getCurrentSession().save(entity); } ......}目錄結(jié)構(gòu):

java - spring事務(wù)不回滾

求大神幫忙看看,調(diào)了一天了,感激不盡。

問題解答

回答1:

看了看,你對service接口進(jìn)行事務(wù)管理,而不是controller你拋出異常是在controller,當(dāng)然不會事務(wù)回滾啦

你試試在sevice實現(xiàn)類中,save一下,再拋個異常,看看save成功不成功

ps一下:mysql有兩個存儲引擎(常用),一個是InnoDB一個是MyISAM,前者支持行級鎖,事務(wù),外鍵,后者不支持

回答2:

樓上說的沒錯,spring事務(wù)作用于service層,當(dāng)遇到service方法拋出異常時,事務(wù)將回滾。所以你的正確測試實踐應(yīng)該是在service層方法中拋出異常。

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 欧美精品网址 | 成年女人毛片免费观看97 | 欧美亚洲另类久久综合 | 国产性自爱拍偷在在线播放 | 国产精品videosse | 国产精品99久久久久久小说 | 91久久香蕉国产线看 | 三级黄色片网站 | 96精品视频在线播放免费观看 | 国产精品久久久久a影院 | 色爱综合网 | 亚州免费一级毛片 | 亚洲午夜在线 | 欧美日韩精品一区二区 | 538在线视频二三区视视频 | 成人性视频在线三级 | 国产精品视频永久免费播放 | 免费国产a国产片高清不卡 免费国产不卡午夜福在线 免费国产不卡午夜福在线观看 | 欧美极品在线视频 | 亚洲欧美日韩精品久久 | 久久99久久精品免费思思6 | 国产一区二区三区欧美精品 | 久久国产欧美日韩精品免费 | www.久久在线 | 天天夜天干天天爽 | 亚洲网在线观看 | 亚洲视频偷拍自拍 | 欧美一级毛片欧美大尺度一级毛片 | 亚洲男人的天堂久久无 | 亚洲制服欧美自拍另类 | 亚州一区二区 | 久久精品国产91久久综合麻豆自制 | 国产亚洲精品久久久久久午夜 | 91免费永久国产在线观看 | 免费观看视频成人国产 | 欧美激情亚洲色图 | 精品一区二区三区的国产在线观看 | 姐姐真漂亮在线视频中文版 | 九一国产精品视频 | 男女乱淫免费视频 | 亚洲在线观看免费视频 |