- 浏览: 213890 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (344)
- Spring (38)
- Spring-mvc (9)
- hibernate (21)
- mvn (5)
- shiro (2)
- java script (14)
- jquery (9)
- ext (6)
- asm (1)
- 大数据 (2)
- 分布式 (14)
- node.js (1)
- webservice (4)
- java (47)
- oracle (36)
- mysql (11)
- sql (33)
- 工具 (13)
- github (3)
- tomcat (4)
- jetty (1)
- struts2 (1)
- android (13)
- xml (1)
- primefaces (1)
- secure (2)
- 编码 (3)
- EL (3)
- jsp (2)
- css (7)
- java 算法 (3)
- 移动端 (2)
- other (3)
- mybatis (1)
- 缓存 (1)
- 乱 (1)
- apache commons (2)
- ehcache (1)
- 方法论 (1)
- activiti (1)
- sqlserver (5)
- 业务 (4)
- 数据结构 (5)
- liux (1)
- commons (4)
- jvm (2)
最新评论
-
张yyyyyy:
不明觉厉
一次sql 调优心得 -
masuweng:
某一类日期范围内每7天一组的销量之和,以及行转列 -
faradayroger:
[color=green][color=red][/color ...
定时JOB,去请求数据,并找出最新数据持久化 -
cainiao1923:
java-lxm 写道 写文章贴个图也不好好贴....难道是网 ...
spring 注入static属性 -
java-lxm:
写文章贴个图也不好好贴
spring 注入static属性
We’re using the Spring Framework in most of our applications (and thus also in the Catalysts Platform) and are really satisfied with it.
One of the big advantages is the the declarative transaction handling using the @Transactional attribute.
import org.springframework.transaction.Transactional;
@Transactional
public class MyService implements IMyService {
public List getResults () {
// do something
}
public void foo() {
throw new java.lang.UnsupportedOperationException();
}
public void bar() {
throw new java.lang.Exception();
}
}
That simple annoation on class managed by a Spring ApplicationContext causes all method calls onto that service to be bound to a transaction. The transaction is committed after the method call has left the service again and it’s rollbacked for the case an exception is thrown (e.g. after calling the (quite silly) method foo()).
But be careful: Only unchecked exceptions (that is, subclasses of java.lang.RuntimeException) are rollbacked by default. For the case, a checked exception is thrown, the transaction will be committed!
The Spring documentation explains that as follows:
While the EJB default behavior is for the EJB container to automatically roll back the transaction on a system exception (usually a runtime exception), EJB CMT does not roll back the transaction automatically on an application exception (that is, a checked exception other than java.rmi.RemoteException). While the Spring default behavior for declarative transaction management follows EJB convention (roll back is automatic only on unchecked exceptions), it is often useful to customize this.
And that customization can be done very easily by just adding the parameter rollBackFor to the @Transactional attribute:
import org.springframework.transaction.Transactional;
@Transactional(rollbackFor = Exception.class)
public class MyService implements IMyService {
public List getResults () {
// do something
}
public void foo() {
throw new java.lang.UnsupportedOperationException();
}
public void bar() {
throw new java.lang.Exception();
}
}
In that case, the transaction will even be be rollbacked on a call to the method bar().
from : https://www.catalysts.cc/en/wissenswertes/spring-transactional-rollback-on-checked-exceptions/
One of the big advantages is the the declarative transaction handling using the @Transactional attribute.
import org.springframework.transaction.Transactional;
@Transactional
public class MyService implements IMyService {
public List getResults () {
// do something
}
public void foo() {
throw new java.lang.UnsupportedOperationException();
}
public void bar() {
throw new java.lang.Exception();
}
}
That simple annoation on class managed by a Spring ApplicationContext causes all method calls onto that service to be bound to a transaction. The transaction is committed after the method call has left the service again and it’s rollbacked for the case an exception is thrown (e.g. after calling the (quite silly) method foo()).
But be careful: Only unchecked exceptions (that is, subclasses of java.lang.RuntimeException) are rollbacked by default. For the case, a checked exception is thrown, the transaction will be committed!
The Spring documentation explains that as follows:
While the EJB default behavior is for the EJB container to automatically roll back the transaction on a system exception (usually a runtime exception), EJB CMT does not roll back the transaction automatically on an application exception (that is, a checked exception other than java.rmi.RemoteException). While the Spring default behavior for declarative transaction management follows EJB convention (roll back is automatic only on unchecked exceptions), it is often useful to customize this.
And that customization can be done very easily by just adding the parameter rollBackFor to the @Transactional attribute:
import org.springframework.transaction.Transactional;
@Transactional(rollbackFor = Exception.class)
public class MyService implements IMyService {
public List getResults () {
// do something
}
public void foo() {
throw new java.lang.UnsupportedOperationException();
}
public void bar() {
throw new java.lang.Exception();
}
}
In that case, the transaction will even be be rollbacked on a call to the method bar().
from : https://www.catalysts.cc/en/wissenswertes/spring-transactional-rollback-on-checked-exceptions/
发表评论
-
spring事务理解
2018-11-01 11:58 2931 传播行为是spring提供的,其他是DB提供的。传播的 ... -
记录一次事务回滚失败,spring mvc环境
2018-10-31 15:36 471<context:component-scan ... -
log4j配置详解(非常详细)
2018-09-05 15:59 373https://www.cnblogs.com/gaishi ... -
JOB调接口大数据 最终版
2017-02-18 14:30 381package jiangdu.fire.job.wj.ba ... -
(转) Spring的quartz定时器同一时刻重复执行二次的问题解决{经测试不可用}
2017-02-16 11:57 356最近用Spring的quartz定时器的时候,发现到时间后, ... -
(转)解决Quartz定时任务被触发两次的问题
2017-02-16 11:54 697摘要: 解决quartz定时任务被触发两次的问题 方法1、 ... -
quartz并发(总结)
2017-02-15 21:20 7781.http://blog.csdn.net/pdw2009 ... -
(转)关于quartz的并发问题
2017-02-15 20:48 7551、quartz默认是多线程的,如果执行任务的对象不是单例的 ... -
@Autowired @Qualifier("userDao") 要配合使用
2017-02-10 15:06 673@Autowired默认是按类型匹配的方式,在容器查找匹配的b ... -
前面博客{定时JOB,去请求数据,并找出最新数据持久化}的问题
2017-01-09 11:03 683之前的博客 定时JOB,去请求数据,并找出最新数据持久 ... -
定时JOB,去请求数据,并找出最新数据持久化
2017-01-07 16:05 1097JOB: /** * 同步警情json 到t_ ... -
断言与异常的区别
2016-12-31 09:02 759断言与异常的区别 断言用在那些你知道绝对不会发生的事情上, ... -
(转)spring beans源码解读之--Bean的注解(annotation)
2017-01-10 17:51 841spring beans源码解读之--Bean的注解( ... -
往非sping管理的类里注入spring对象
2016-12-13 17:20 554http://stackoverflow.com/ques ... -
spring 注入static属性
2016-12-13 16:37 2598网上好多方法都是错误的,google之,发现 ... -
(转)Spring不支持依赖注入static静态变量
2016-12-13 14:34 483在springframework里,我们不能@Autowir ... -
(转)@Autowired、 @Qualifier 与 @Resource
2016-12-02 08:57 5491、@Autowired与@Resource都可以用来 ... -
注入与泛型的一点疑惑
2016-12-01 08:48 397qualifier 会直接注入 commonDao ,不会是 ... -
(转)Spring事务传播特性的浅析——事务方法嵌套调用的迷茫 --深度好文
2016-11-24 14:23 521Spring事务传播机制回 ... -
(转)浅谈Spring事务传播特性、隔离级别
2016-11-18 09:38 529一、Propagation (事务的传播属性) Prop ...
相关推荐
spring事务管理注解jar,spring-tx-3.2.4.RELEASE.jar,导入项目即可
我們使用Spring Framework裡,在Service 的 Method 給予@Transactional 系統就會去管理transaction,我們是在哪裡做了甚麼設定嗎? 為什麼下的這個Annotation成功會commit失敗會rollback呢? Transaction 管理做了...
Spring中@Transactional事务回滚(含实例详细讲解,附源码)Java开发Java经验技巧共8页.pdf.zip
主要介绍了Spring @Transactional工作原理详解,具有一定借鉴价值,需要的朋友可以参考下。
声明式事务管理也有两种常用的方式,一种是基于tx和aop名字空间的xml配置文件,另一种就是基于@Transactional注解。显然基于注解的方式更简单易用,
@Transactional实现原理.txt
Spring3事务管理——使用@Transactional 注解.rar
关于spring中@Transactional注解传播属性原理的实验 具体方法: 主体形式:a方法调用b方法 a插入数据“one” b插入数据“two” a、b方法都可以有不同的传播级别或者不加事务注解(none): required(rd), required_...
本篇文章主要介绍了浅谈Spring中@Transactional事务回滚及示例(附源码),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Spring中的@Transactional事物回滚实例源码
主要介绍了spring的@Transactional注解用法解读,具有一定借鉴价值,需要的朋友可以参考下
在本篇文章里小编给大家整理了关于Spring声明式事务@Transactional详解内容,需要的朋友们可以参考下。
主要介绍了Spring中@Transactional用法详细介绍的相关资料,需要的朋友可以参考下
今天小编就为大家分享一篇关于springboot中事务管理@Transactional的注意事项与使用场景,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
主要介绍了深入学习Spring Boot排查 @Transactional 引起的 NullPointerException问题,需要的朋友可以参考下
本代码使用H2内存数据库演示spring事务使用,包括编程式事务,声明式事务@Transactional使用,自定义事务事务注解实现自定义事务管理器
主要介绍了spring @Transactional 无效的解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
今天我们来探讨一个有意思的spring源码问题,也是一个学生告诉了我现象我从源码里面找到了这个有意思的问题。 首先我们看service层的代码案例,如下: @Service("transationServiceImpl") public class ...
Spring源码学习十二:@Transactional是如何工作的1
主要介绍了Spring @Transactional注解失效解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下