spring-boot 事务异常: because it is a JDK dynamic proxy that implement
来源:互联网 发布:k8网络分销平台 编辑:程序博客网 时间:2024/05/23 23:45
使用spring-boot做事务管理时,出现异常:The bean 'xxx' could not be injected as a 'xx.xxxx' because it is a JDK dynamic proxy that implements:
搞了半天发现是因为代理的原因;
异常信息:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.2017-08-01 09:37:14.845 ERROR 12264 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : ***************************APPLICATION FAILED TO START***************************Description:The bean 'AdapterSchemeVersionService' could not be injected as a 'com.yihu.hos.rest.services.standard.adapter.AdapterSchemeVersionService' because it is a JDK dynamic proxy that implements:Action:Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
使用 @Transactional
开启@Transactional 注解支持,两种方式,一种是通过xml的方式(如下)
<tx:annotation-driven transaction-manager="txManager"/><!-- a PlatformTransactionManager is still required --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <!-- (this dependency is defined somewhere else) --> <property name="dataSource" ref="dataSource"/> </bean>
@EnableTransactionManagement
,将该注解标注在@Configuration
类上,等价于上面的<tx:annotation-driven/>
Spring推荐奖该注解标记在类(方法)而不是接口,将注解标记在接口上时,只有使用动态代理的时候才会生效,需要标记
proxy-target-class="true"
或者mode="aspectj",如下:
@Configuration@EnableTransactionManagement(proxyTargetClass = true)@ComponentScan("com.yihu.hos.rest")public class BeanConfiguration {}
@Transaction
的类会自动开启动态代理,java的代理机制主要有JDK动态代理和CGLIB,报上面的错误是因为使用了JDK动态代理机制,我尝试开启@Transaction设置@EnableTransactionManagement(proxyTargetClass = true)
,问题解决;特此记录一下;参考文章:http://hrps.me/2016/11/03/spring-transaction/
阅读全文
0 0
- spring-boot 事务异常: because it is a JDK dynamic proxy that implement
- The disk is offline because it has a signature collision with another disk that is online
- Spring boot中出现JDK dynamic proxy使用@Resource注入实例出现问题
- Unable to proxy method HibernateDaoSupport.setHibernateTemplate because it is final
- Spring Boot 出现 in a frame because it set 'X-Frame-Options' to 'DENY'
- cheap louboutin shoes It is said that a couple of lofty heels namely the important"weapon"because al
- poj 3278 Catch That Cow If I know what love is, it is because of you
- Creating a Dynamic Proxy
- war exploded' because it is included into a circular dependency
- JDK Dynamic Proxy and cglib
- jdk Dynamic Proxy 动态代理
- Which will declare a method that forces a subclass to implement it
- MySQL test: it’s because of RQG that we now have a really solid MySQL Server
- spring使用中报Cannot proxy target class because CGLIB2 is not available错
- [Sprincglib] spring aop报错:Cannot proxy target class because CGLIB2 is not available.
- Spring 错误Cannot proxy target class because CGLIB2 is not available
- spring aop报错:Cannot proxy target class because CGLIB2 is not available.
- The Maven Integration requires that Eclipes be running in a JDK because a number o eclipes加载maven出错
- HDOJ 1016 Prime Ring Problem(DFS + STL容器)
- Android 透明度alpha换算表
- Gradle使用Maven默认仓库
- python实现随机梯度下降法
- 处理Cocos2dx乱码问题
- spring-boot 事务异常: because it is a JDK dynamic proxy that implement
- Keras/Theano/OpenCV实现的CNN手势识别
- 定时器(scheduler)的使用
- Wayland的前世与今生(二)------我的后半生
- spring 整合 quartz
- 进度条的实现(ProgressTimer)
- 112_容器_数据存储练习_JavaBean的介绍
- Linux 正则表达式与通配符
- MFC多线程编程