-
Notifications
You must be signed in to change notification settings - Fork 503
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,6 +276,12 @@ | |
<version>1.2.17</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.data</groupId> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
<artifactId>spring-data-jpa</artifactId> | ||
<version>2.5.1</version> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
|
||
<reporting> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.retry.annotation; | ||
|
||
import org.springframework.aop.Advisor; | ||
import org.springframework.aop.framework.Advised; | ||
import org.springframework.aop.framework.ProxyFactory; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation; | ||
import org.springframework.retry.interceptor.Retryable; | ||
|
||
/** | ||
* Add a bean of this instance if you wish to annotate JPA Repository interfaces with | ||
* {@code @Retryable}. It merges the repository proxy advisors with the retry advisor. | ||
* | ||
* @author Gary Russell | ||
* @since 1.3.2 | ||
*/ | ||
public class JPARepositoryRetryBeanPostProcessor implements BeanPostProcessor, Ordered { | ||
|
||
@Override | ||
public int getOrder() { | ||
return Integer.MAX_VALUE; | ||
} | ||
|
||
@Override | ||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
if (bean instanceof Retryable && bean instanceof Advised) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could generally check if the bean implements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks Mark; without removing that interface, I get
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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
Advised advised = (Advised) bean; | ||
try { | ||
Object target = advised.getTargetSource().getTarget(); | ||
if (target instanceof Advised) { | ||
Advised advised2 = (Advised) target; | ||
Object target2 = advised2.getTargetSource().getTarget(); | ||
if (target2 != null) { | ||
ProxyFactory pf = new ProxyFactory(target2); | ||
pf.removeInterface(JpaRepositoryImplementation.class); | ||
for (Advisor advisor : advised.getAdvisors()) { | ||
pf.addAdvisor(advisor); | ||
} | ||
for (Advisor advisor : advised2.getAdvisors()) { | ||
pf.addAdvisor(advisor); | ||
} | ||
for (Class<?> iface : advised2.getProxiedInterfaces()) { | ||
pf.addInterface(iface); | ||
} | ||
return pf.getProxy(); | ||
} | ||
} | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return bean; | ||
} | ||
|
||
@Override | ||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { | ||
return bean; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.