Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-214: Retryable on JPA Repos with proxyTargetClass [DO NOT MERGE] #246

Closed
wants to merge 1 commit into from

Conversation

garyrussell
Copy link
Contributor

Resolves #214

When proxyTargetClass is true (Boot's default), the JPA interfaces
are not copied to the outer retry proxy created by auto-proxy.

Add a BPP to fix up the proxy, when needed.

Also, the pointcut filter must match on the SimpleJpaRepository.

Resolves spring-projects#214

When `proxyTargetClass` is `true` (Boot's default), the JPA interfaces
are not copied to the outer retry proxy created by auto-proxy.

Add a BPP to fix up the proxy, when needed.

Also, the pointcut filter must match on the `SimpleJpaRepository`.
@garyrussell
Copy link
Contributor Author

cc/ @mp911de

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if we want to dig into a discussion to make this work for all Spring Data repository implementations. Would be probably easier than keeping code for all kinds of Spring Data modules around.

@@ -596,6 +596,13 @@ line to your `build.gradle` file:
runtime('org.aspectj:aspectjweaver:1.8.13')
```

### Using Declarative Retry on Spring JPA Repository Interfaces
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to generally allow Spring Data repositories.

@@ -276,6 +276,12 @@
<version>1.2.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest using Spring Data Commons to enable retry functionality for all Spring Data modules.


@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Retryable && bean instanceof Advised) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could generally check if the bean implements org.springframework.data.repository.Repository (as marker for Spring Data repositories) to make this work for all Spring Data modules. Not sure why JpaRepositoryImplementation` needs to be excluded here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Mark; without removing that interface, I get

Caused by: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress, and that the CrudMethodMetadataPopulatingMethodInterceptor is upfront in the interceptor chain.
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.currentInvocation(CrudMethodMetadataPostProcessor.java:129) ~[spring-data-jpa-2.5.1.jar:2.5.1]
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$ThreadBoundTargetSource.getTarget(CrudMethodMetadataPostProcessor.java:322) ~[spring-data-jpa-2.5.1.jar:2.5.1]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:195) ~[spring-aop-5.3.7.jar:5.3.7]

I am going to close this PR for now, and open an issue against spring-aop, to see if we can get the root cause fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spring-projects/spring-framework#27044

Let's see what the framework guys say before doing any more.

@garyrussell garyrussell changed the title GH-214: Retryable on JPA Repos with proxyTargetClass GH-214: Retryable on JPA Repos with proxyTargetClass [DO NOT MERGE] Jun 9, 2021
@garyrussell garyrussell closed this Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spring-Retry @Retryable not working with Spring-data Repositories
2 participants