【发布时间】:2017-08-01 11:45:38
【问题描述】:
在我的 spring-data-cassandra 存储库接口添加@Retryable 注释后,现在应用程序无法启动并出现以下异常:
应用程序启动失败
The bean 'airingDao' could not be injected as a 'my.dao.AiringDao' because it is a JDK dynamic proxy that implements:
org.springframework.data.cassandra.repository.CassandraRepository
行动:
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.
将proxyTargetClass=true 添加到@EnableAsync 和@EnableCaching,甚至添加到@EnableRetry(proxyTargetClass = true)
@EnableAspectJAutoProxy(proxyTargetClass = true)
但还是不行。
删除@Retryable 后,一切正常。
检查代码,没有@Retryable,在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(String, Class<T>, Object[], boolean)
bean.getClass().getInterfaces()
(java.lang.Class<T>[]) [interface my.dao.AiringDao, interface
org.springframework.data.repository.Repository, interface
org.springframework.transaction.interceptor.TransactionalProxy, interface
org.springframework.aop.framework.Advised, interface
org.springframework.core.DecoratingProxy]
所以requiredType.isAssignableFrom(bean.getClass()) 是true
但是加了@Retryable之后:
bean.getClass().getInterfaces()
(java.lang.Class<T>[]) [interface
org.springframework.retry.interceptor.Retryable, interface
org.springframework.aop.SpringProxy, interface
org.springframework.aop.framework.Advised, interface
org.springframework.core.DecoratingProxy]
所以现在requiredType.isAssignableFrom(bean.getClass())) 是false 并且getTypeConverter().convertIfNecessary(bean, requiredType) 抛出异常。
任何人都可以帮助或提供一些解决问题的线索吗? 感谢您的帮助。
【问题讨论】:
-
你用
spring-retry做什么? -
我正在尝试添加@Retryable 来保存实现CassandraRepository 的接口中的方法。 - 也许它不是一个有效的案例:)
-
Jens Schauder 的answer 中的第二种方法是解决此问题的最佳方法。请注意,使用
@Retryable注释类/接口会向其中的所有方法(公共)添加重试。
标签: java spring cassandra spring-data spring-retry