Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@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:

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)

But still doesn't work.

After I remove the @Retryable, every thing works fine.

Checked the code, without @Retryable, in 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

But after added @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.

Could anyone please help or provide some clue how to troubleshoot it? Thanks for your help.

like image 954
jeffery.yuan Avatar asked Oct 30 '25 20:10

jeffery.yuan


2 Answers

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. 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.

  2. Introduce a separate layer for you @Retry which you then let delegate to your Spring Data repositories.

Of course those approaches aren't mutual exclusive.

like image 95
Jens Schauder Avatar answered Nov 02 '25 10:11

Jens Schauder


Here is a workaround provided. I raised an issue for this in Spring-Retry GitHub.

Spring-Retry Github Issue

like image 26
pj2494 Avatar answered Nov 02 '25 09:11

pj2494



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!