【问题标题】:@Retryable doesn't work in spring-data repository interface@Retryable 在 spring-data 存储库接口中不起作用
【发布时间】: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


【解决方案1】:

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

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

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

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

【讨论】:

    【解决方案2】:

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

    Spring-Retry Github Issue

    【讨论】:

      猜你喜欢
      • 2019-03-02
      • 2015-12-29
      • 2015-02-13
      • 2012-06-02
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 2019-10-21
      • 2018-02-11
      相关资源
      最近更新 更多