spring-boot 事务异常: because it is a JDK dynamic proxy that implement
2017-08-01 09:40
1621 查看
使用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>
另外一种是使用
Spring推荐奖该注解标记在类(方法)而不是接口,将注解标记在接口上时,只有使用动态代理的时候才会生效,需要标记
@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
@ComponentScan("com.yihu.hos.rest")
public class BeanConfiguration {}
因为加了
参考文章:http://hrps.me/2016/11/03/spring-transaction/
搞了半天发现是因为代理的原因;
异常信息:
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/
相关文章推荐
- The bean 'xxx' could not be injected as a 'xxx'because it is a JDK dynamic proxy that
- Spring Boot中使用Feign调用时Hystrix提示异常:"could not be queued for execution and no fallback available."以及"Rejected command because thread-pool queueSize is at rejection threshold"
- Spring boot中出现JDK dynamic proxy使用@Resource注入实例出现问题
- 使用子事务(saveponit)时,当子事务抛出异常后,此异常处理掉不继续往外抛, Transaction has been rolled back because it has been marke
- springboot-拦截器-过滤器-Required request body is missing 异常
- C#使用Create创建文件后,报The Process cannot access the file because it is being used by another process的异常
- 浅谈Spring声明式事务管理ThreadLocal和JDKProxy
- MySQL触发器更新本表数据异常:Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this
- DWF整合spring异常:**ScopedProxyUtils.isScopedTarget
- The disk is offline because it has a signature collision with another disk that is online
- 异常-----Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat> or ?string(format) built-
- 异常 The type org.springframework...DaoSupport cannot be resolved. It is indirectly...
- C#使用Create创建文件后,报The Process cannot access the file because it is being used by another process的异常
- MySQL触发器更新本表数据异常:Can’t update table ‘tbl’ in stored function/trigger because it is already used by s
- spring事务 Transaction rolled back because it has been marked as rollback-only
- Assertion failed: Cancelling DisplayDialog because it was run from a thread that is not the main 。。
- Spring结合Hibernate出现的异常The type org.springframework...DaoSupport cannot be resolved. It is indirectly...(
- Unable to proxy method HibernateDaoSupport.setHibernateTemplate because it is final
- spring 事务异常Failed to convert property value of type [$Proxy12] to required type
- 九、SpringBoot异常之基于SpringMVC提供的注解