当前位置:网站首页>@Configuration, use, principle and precautions of transmission:
@Configuration, use, principle and precautions of transmission:
2022-07-07 10:23:00 【thoughtCodes】
One . Use :
@Transactional Annotations can act on interfaces 、 Interface method 、 Class and class methods , however Spring It is not recommended to use this annotation on interfaces or interface methods , Because it only works when using an interface based proxy .
@Transactional Annotations should only be applied to public On the way , This is from Spring AOP The essence of the decision . If you are in the protected、private Or the default visibility method @Transactional annotation , This will be ignored , No exceptions will be thrown .
By default , Only method calls from outside will be AOP Agent capture , That is to say , Even if used by the calling method @Transactional To modify , Calling other methods inside this class does not cause transactional behavior . ( The following example 1 This is a good example )
@Transactional annotation , In case of unchecked exception, It will happen rollback. That is to say, the exception thrown is RuntimeException Subclasses of (Errors It also causes transaction rollback ), And throw checked Exception will not cause transaction rollback . Sum up :NullPointerException Will roll back , image IOException、 Network class exception It won't roll back .
When ( Application tested )unchecked exception By try - catch when Will not be rolled back .
and Cheacked Exception, Also known as “ Exception checked ”, Such as IOException、SQLException And user-defined Exception abnormal . Such exceptions must be handled at compile time , Otherwise, it cannot be compiled .
@Transcation By default, only rollback (JVM Level ) Throw out RuntimeException And Error Abnormal transactions , So by default, if you throw SQLException、IOException You cannot rollback a transaction without processing .
error It's bound to roll back
Java Language norms will derive from Error class or RuntimeException All exceptions of the class become unobserved (unchecked) abnormal , All other exceptions (OI,net) Called observed (checked) abnormal .
Two . principle :
dynamic aop The way of weaving
3. Precautions .
Not specified RollbackOn, And the exception thrown is not RuntimeException
Therefore, Alibaba code specification initiative is to show the specified rollbackOn by Exception
Recommended reading :
https://blog.csdn.net/weixin_45433603/article/details/107959487?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-0-107959487-blog-121939722.pc_relevant_aa2&spm=1001.2101.3001.4242.1&utm_relevant_index=3
https://blog.csdn.net/maomaoqiukqq/article/details/103941157
https://blog.csdn.net/qq_35387940/article/details/107245613
边栏推荐
- 【剑指Offer】42. 栈的压入、弹出序列
- table宽度比tbody宽度大4px
- Use of JSON extractor originals in JMeter
- 柏拉图和他的三个弟子的故事:如何寻找幸福?如何寻找理想伴侣?
- 0x0fa23729 (vcruntime140d.dll) (in classes and objects - encapsulation.Exe) exception thrown (resolved)
- Embedded background - chip
- ORM model -- associated fields, abstract model classes
- Fiddler simulates the interface test
- STM32 Basics - memory mapping
- Review of the losers in the postgraduate entrance examination
猜你喜欢
Serial communication relay Modbus communication host computer debugging software tool project development case
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Several schemes of building hardware communication technology of Internet of things
01 use function to approximate cosine function (15 points)
LLVM之父Chris Lattner:為什麼我們要重建AI基礎設施軟件
Weekly recommended short videos: what are the functions of L2 that we often use in daily life?
PDF文档签名指南
Embedded background - chip
基于gis三维可视化技术的智慧城市建设
[second on] [jeecgboot] modify paging parameters
随机推荐
Memory ==c language 1
Vs code specifies the extension installation location
Advanced function learning in ES6
JMeter about setting thread group and time
Some thoughts on the testing work in the process of R & D
[email protected]能帮助我们快速拿到日志对象
2022.7.6DAY598
Study summary of postgraduate entrance examination in October
ORM -- grouping query, aggregation query, query set queryset object properties
When there are pointer variable members in the custom type, the return value and parameters of the assignment operator overload must be reference types
Chris Lattner, père de llvm: Pourquoi reconstruire le logiciel d'infrastructure ai
Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
Guide de signature du Code Appx
The story of Plato and his three disciples: how to find happiness? How to find the ideal partner?
Use the fetch statement to obtain the repetition of the last row of cursor data
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Interface test
Study summary of postgraduate entrance examination in November