简体   繁体   English

@Retryable 在 spring-data 存储库接口中不起作用

[英]@Retryable doesn't work in spring-data repository interface

After I added @Retryable annotation to my spring-data-cassandra repository interface, now the application fails to start with following exception:在我将@Retryable注释添加到我的 spring-data-cassandra 存储库界面后,现在应用程序无法启动,出现以下异常:

APPLICATION FAILED TO START应用程序无法启动

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

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.

Added proxyTargetClass=true to @EnableAsync and @EnableCaching , even to @EnableRetry(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)proxyTargetClass=true添加到@EnableAsync@EnableCaching ,甚至添加到@EnableRetry(proxyTargetClass = true) @EnableAspectJAutoProxy(proxyTargetClass = true)

But still doesn't work.但仍然不起作用。

After I remove the @Retryable , every thing works fine.删除@Retryable ,一切正常。

Checked the code, without @Retryable , in org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(String, Class<T>, Object[], boolean)检查代码,没有@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]

So requiredType.isAssignableFrom(bean.getClass()) is true所以requiredType.isAssignableFrom(bean.getClass())true

But after added @Retryable :但是在添加@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]

So now requiredType.isAssignableFrom(bean.getClass())) is false and getTypeConverter().convertIfNecessary(bean, requiredType) throws the exception.所以现在requiredType.isAssignableFrom(bean.getClass()))false并且getTypeConverter().convertIfNecessary(bean, requiredType)抛出异常。

Could anyone please help or provide some clue how to troubleshoot it?任何人都可以请帮助或提供一些线索如何解决它? Thanks for your help.谢谢你的帮助。

Don't know Spring Retry, and haven't checked in detail, but I suspect, that there is no integration between Spring Data and Spring Retry yet.不知道Spring Retry,也没有详细查过,但我怀疑,Spring Data和Spring Retry之间还没有集成。 If this is true, you have two approaches available to you:如果这是真的,您可以使用两种方法:

  1. Open an issue on Spring Data or Spring Retry to get the integration implemented.在 Spring Data 或 Spring Retry 上打开一个问题以实现集成。

  2. Introduce a separate layer for you @Retry which you then let delegate to your Spring Data repositories.为您引入一个单独的层@Retry然后让您委托给您的 Spring Data 存储库。

Of course those approaches aren't mutual exclusive.当然,这些方法并不是相互排斥的。

Here is a workaround provided.这是提供的解决方法。 I raised an issue for this in Spring-Retry GitHub.我在 Spring-Retry GitHub 中为此提出了一个问题。

Spring-Retry Github Issue Spring-Retry Github 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM