当前位置:网站首页>@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
边栏推荐
- [email protected]能帮助我们快速拿到日志对象
- High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors
- Some test points about coupon test
- Review of the losers in the postgraduate entrance examination
- . Net configuration system
- The Hal library is configured with a general timer Tim to trigger ADC sampling, and then DMA is moved to the memory space.
- IO模型复习
- Postman interface test VI
- 【华为机试真题详解】高矮个子排队
- Google colab loads Google drive (Google drive is used in Google colab)
猜你喜欢
The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
浅谈日志中的返回格式封装格式处理,异常处理
HAL库配置通用定时器TIM触发ADC采样,然后DMA搬运到内存空间。
Smart city construction based on GIS 3D visualization technology
Some properties of leetcode139 Yang Hui triangle
串口通讯继电器-modbus通信上位机调试软件工具项目开发案例
This article explains the complex relationship between MCU, arm, muc, DSP, FPGA and embedded system
ArcGIS operation: converting DWG data to SHP data
Postman interface test IV
一文讲解单片机、ARM、MUC、DSP、FPGA、嵌入式错综复杂的关系
随机推荐
Postman tutorial - scripting
【HigherHRNet】 HigherHRNet 详解之 HigherHRNet的热图回归代码
Google colab loads Google drive (Google drive is used in Google colab)
PDF文档签名指南
Some test points about coupon test
Some properties of leetcode139 Yang Hui triangle
【acwing】786. Number k
A wave of open source notebooks is coming
【剑指Offer】42. 栈的压入、弹出序列
Study summary of postgraduate entrance examination in October
Word自动生成目录的方法
. Net configuration system
Guid主键
Study summary of postgraduate entrance examination in August
Es classes and objects, prototypes
移动端通过设置rem使页面内容及字体大小自动调整
The landing practice of ByteDance kitex in SEMA e-commerce scene
Leetcode exercise - 113 Path sum II
mysql插入数据创建触发器填充uuid字段值
[ORM framework]