Spring mvc注解方式使用事务回滚
来源:互联网 发布:旭辉研彩软件官网 编辑:程序博客网 时间:2024/06/16 00:30
项目名:1ma1ma
jdbc.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
p:maxActive="${jdbc.pool-size}"
p:minEvictableIdleTimeMillis="600000" p:timeBetweenEvictionRunsMillis="900000"
p:removeAbandoned="true" p:logAbandoned="true" p:removeAbandonedTimeout="120"
p:maxWait="5000"
/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<context:component-scan base-package="com.yaoma.*">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
servlet-context.xml
<context:component-scan base-package="com.yaoma.*" >
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
@Transactional
public int delete(String IMGroupID, String userid) throws Exception {
//按照IMGroupID和userid更新对应的Groups表内容
int is_return = Groups_Dao.IsDeleted_Groups(IMGroupID, userid, 0);
if (is_return == 0) {
throw new RuntimeException("is_return is 0;");
}
//去环信上删除对应的数据
String hx_return = HX_Service.delete_group(IMGroupID);
if (hx_return == null) {
throw new RuntimeException("hx_return is null");
}
return Integer.parseInt(hx_return);
}
@Transactional注解标签
因为在运行中,所以使用RuntimeException进行异常抛出,类中不能使用try捕捉异常,直接throws Exception抛出异常
如运行时使用Exception抛出异常,则回滚无效
- Spring mvc注解方式使用事务回滚
- Spring MVC @Transactional注解方式事务无法回滚的解决办法
- Spring MVC 注解事务 之 异常回滚
- Spring 使用注解方式进行事务管理--注解回滚机制
- Spring注解事务提交回滚
- spring注解事务及事务回滚失败的原因
- [spring,mysql] spring使用注解式事务声明(@Transactional)无法回滚
- spring mvc事务注解
- Spring事务回滚
- spring事务回滚
- spring事务回滚
- spring事务回滚
- spring回滚事务
- spring 事务回滚
- spring 事务回滚
- spring事务回滚
- Spring事务回滚
- [Spring]事务回滚
- getaddrinfo(),freeaddrinfo(), gai_strerror()函数详解
- Linux dd 命令详解
- c++下 遍历 lua table
- CentOS 6.4中升级编译安装GCC 4.8.1 + GDB 7.6.1 + Eclipse 以及Kdump配置
- 分布式MySQL数据库TDSQL架构分析
- Spring mvc注解方式使用事务回滚
- Android进步之路四:SimpleAdapter类的具体用法
- 使用流畅的pdf分割软件
- C++细节学习之const对象只能调用const函数
- 从窗口到视口的映射
- Mac快捷键
- HITS(HITS(Hyperlink - Induced Topic Search) ) 算法
- 使用 Eclipse Memory Analyzer 进行堆转储文件分析
- Notification 的使用