事务注解@Transactional
spring使用注解事务的时候,需要在配置文件里面进行如下配置:
<!--开启注解事务-->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
proxy-target-class
proxy-target-class=“true”
基于类的代理将起作用(cglib库)
proxy-target-class=“false”
基于接口的代理将起作用(标准的JDK,默认选项)
高版本spring自动根据运行类选择JDK或CGLIB代理
cglib动态代理和jdk动态代理的区别
JDK动态代理只能对实现了接口的类生成代理,而不能针对类。
CGLIB是针对类实现代理,主要是对指定的类生成一个子类,覆盖其中的方法,因为是继承,所以该类或者方法最好不要生命成final。
proxy-target-class在spring事务、aop、缓存这几块都有设置,其作用都是一样的
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<aop:config proxy-target-class="true">
<cache:annotation-driven proxy-target-class="true"/>
事务异常
在service方法上加@Transactional注解,或者在@Component类加@Transactional注解,报错but was actually of type [com.sun.proxy.$Proxy72]
错误日志
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field:
nested exception is java.lang.IllegalArgumentException: com.sun.proxy.$Proxy72
解决方法
加proxy-target-class="true"属性
思想
要了解人们提出意见的过程和逻辑
无论你向谁提问,对方一般都会提供“答案”,所以要仔细考虑向谁提问
让每个人都可肆意评论其他人的观点,此举低效且浪费时间。
提防以“我以为…”为开头的发言。
系统梳理员工的工作记录,评估其发言的可信度。