mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-16 18:10:13 +08:00
Update SpringInterviewQuestions.md
This commit is contained in:
parent
8705227daf
commit
27f8743a0a
@ -270,12 +270,21 @@ public OneService getService(status) {
|
||||
|
||||
- **TransactionDefinition.PROPAGATION_NESTED:** 如果当前存在事务,则创建一个事务作为当前事务的嵌套事务来运行;如果当前没有事务,则该取值等价于TransactionDefinition.PROPAGATION_REQUIRED。
|
||||
|
||||
## @Transactional(rollbackFor = Exception.class)注解了解吗?
|
||||
|
||||
我们知道:Exception分为运行时异常RuntimeException和非运行时异常。事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性。
|
||||
|
||||
当`@Transactional`注解作用于类上时,该类的所有 public 方法将都具有该类型的事务属性,同时,我们也可以在方法级别使用该标注来覆盖类级别的定义。如果类或者方法加了这个注解,那么这个类里面的方法抛出异常,就会回滚,数据库里面的数据也会回滚。
|
||||
|
||||
在`@Transactional`注解中如果不配置`rollbackFor`属性,那么事物只会在遇到`RuntimeException`的时候才会回滚,加上`rollbackFor=Exception.class`,可以让事物在遇到非运行时异常时也回滚
|
||||
|
||||
## 参考
|
||||
|
||||
- 《Spring 技术内幕》
|
||||
- <http://www.cnblogs.com/wmyskxz/p/8820371.html>
|
||||
- <https://www.journaldev.com/2696/spring-interview-questions-and-answers>
|
||||
- <https://www.edureka.co/blog/interview-questions/spring-interview-questions/>
|
||||
- https://www.cnblogs.com/clwydjgs/p/9317849.html
|
||||
- <https://howtodoinjava.com/interview-questions/top-spring-interview-questions-with-answers/>
|
||||
- <http://www.tomaszezula.com/2014/02/09/spring-series-part-5-component-vs-bean/>
|
||||
- <https://stackoverflow.com/questions/34172888/difference-between-bean-and-autowired>
|
||||
|
Loading…
x
Reference in New Issue
Block a user