Skip to content

Commit 27f8743

Browse files
committed
Update SpringInterviewQuestions.md
1 parent 8705227 commit 27f8743

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/system-design/framework/spring/SpringInterviewQuestions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,21 @@ public OneService getService(status) {
270270

271271
- **TransactionDefinition.PROPAGATION_NESTED:** 如果当前存在事务,则创建一个事务作为当前事务的嵌套事务来运行;如果当前没有事务,则该取值等价于TransactionDefinition.PROPAGATION_REQUIRED。
272272

273+
## @Transactional(rollbackFor = Exception.class)注解了解吗?
274+
275+
我们知道:Exception分为运行时异常RuntimeException和非运行时异常。事务管理对于企业应用来说是至关重要的,即使出现异常情况,它也可以保证数据的一致性。
276+
277+
`@Transactional`注解作用于类上时,该类的所有 public 方法将都具有该类型的事务属性,同时,我们也可以在方法级别使用该标注来覆盖类级别的定义。如果类或者方法加了这个注解,那么这个类里面的方法抛出异常,就会回滚,数据库里面的数据也会回滚。
278+
279+
`@Transactional`注解中如果不配置`rollbackFor`属性,那么事物只会在遇到`RuntimeException`的时候才会回滚,加上`rollbackFor=Exception.class`,可以让事物在遇到非运行时异常时也回滚
280+
273281
## 参考
274282

275283
- 《Spring 技术内幕》
276284
- <http://www.cnblogs.com/wmyskxz/p/8820371.html>
277285
- <https://www.journaldev.com/2696/spring-interview-questions-and-answers>
278286
- <https://www.edureka.co/blog/interview-questions/spring-interview-questions/>
287+
- https://www.cnblogs.com/clwydjgs/p/9317849.html
279288
- <https://howtodoinjava.com/interview-questions/top-spring-interview-questions-with-answers/>
280289
- <http://www.tomaszezula.com/2014/02/09/spring-series-part-5-component-vs-bean/>
281290
- <https://stackoverflow.com/questions/34172888/difference-between-bean-and-autowired>

0 commit comments

Comments
 (0)