2

在我向 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()))falsegetTypeConverter().convertIfNecessary(bean, requiredType)抛出异常。

任何人都可以请帮助或提供一些线索如何解决它?谢谢你的帮助。

4

2 回答 2

2

不知道Spring Retry,也没有详细检查过,但是我怀疑Spring Data和Spring Retry之间还没有集成。如果这是真的,您可以使用两种方法:

  1. 在 Spring Data 或 Spring Retry 上打开一个问题以实现集成。

  2. 为您引入一个单独的层,@Retry然后将其委托给您的 Spring Data 存储库。

当然,这些方法并不是相互排斥的。

于 2017-03-11T08:59:37.730 回答
1

这是提供的解决方法。我在 Spring-Retry GitHub 中为此提出了一个问题。

Spring-Retry Github 问题

于 2020-09-07T05:38:22.807 回答