Spring mvc注解方式使用事务回滚
2015-06-02 11:02
531 查看
项目名: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抛出异常,则回滚无效
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抛出异常,则回滚无效
相关文章推荐
- 使用 Eclipse Memory Analyzer 进行堆转储文件分析
- eclipse中自动补齐代码设置
- java的延时
- Java多线程系列--“基础篇”10之 线程优先级和守护线程
- 利用Eclipse处理臃肿代码的方法
- java处理Excel文件---excel文件的创建,删除,写入,读取
- java处理Excel文件---excel文件的创建,删除,写入,读取
- MyEclipse 的Web项目移植到Eclipse中无法添加到Tomca
- Struts2标签库详解(转载)
- 严重: Exception starting filter struts2解决方法!
- java字符操作获取汉字的拼音以及其他常用工具
- Java中Serializable浅谈
- Java for LeetCode 134 Gas Station
- Java 并发编程框架(一)
- Java 排序算法
- 【转】【java】java中的byte,以及它与int的转化
- Java 并发编程框架(二)
- Java for LeetCode 133 Clone Graph
- Spring Mvc工作原理
- Java 序列化