av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

java - spring事務不回滾

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

問題描述

1.spring事務不會回滾,網上的方法都試過了,沒有效果。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

<!-- 配置事務管理器 --> <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); } ......}目錄結構:

java - spring事務不回滾

求大神幫忙看看,調了一天了,感激不盡。

問題解答

回答1:

看了看,你對service接口進行事務管理,而不是controller你拋出異常是在controller,當然不會事務回滾啦

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

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

回答2:

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

標簽: java
相關文章:
主站蜘蛛池模板: 成人深夜 | 91午夜理伦私人影院 | 亚洲第一黄色 | 国产一级免费视频 | 日本特黄一级片 | 91精品国产一区二区三区 | 国产精品国产三级国产 | 欧洲av网站| 亚洲免费福利视频 | av福利在线观看 | 中文字幕在线观看免费视频 | 成人一级黄色片 | 男女啪啪免费视频 | 久久久久久艹 | 伊人网av | 国产黄色在线播放 | 国产又粗又大又硬 | 四虎四虎 | 免费中文字幕 | 少妇高潮露脸国语对白 | 在线午夜视频 | 国产黄视频在线观看 | 三级视频在线观看 | 亚洲第一在线 | 国产欧美久久久 | 日韩免费精品视频 | 在线不卡一区 | 久久夜色精品国产欧美乱极品 | 亚洲手机在线 | 白浆在线| 91av视频在线观看 | 特级西西444www大胆免费看 | 在线网站免费观看18 | 日韩在线免费播放 | 亚洲乱色| 国产精品成人一区二区三区 | 国产高清在线观看 | 精品视频免费在线观看 | 国产com| 国产精品一区二区三 | 久久天天躁狠狠躁夜夜躁2014 |