forked from spring-attic/spring-framework-issues
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and demonstrate workaround for SPR-8639
As originally submitted, SPR-8639 used ProxyFactoryBean to apply MyInterceptor to beans A, B and C. Typically this works fine, but because of a subtle circular dependency being introduced due to A and B depending on C and C needing to autowire D, the PFBs for A and B are prematurely queried for their type (to see if they are autowire candidates for C) and this trigger a BeanAlreadyInCreation exception that is subsequently suppressed. This is a very specific use case and highly unlikely to be reproduced by other users with any frequency. However, we will address it even if only by allowing the original exception to propagate fully. In the meantime, I have refactored the test case to demonstrate use of BeanNameAutoProxyCreator in lieu of the original ProxyFactoryBean, and this approach is better in every way: it is more concise, more readable, requires fewer bean definitions, and best of all does not suffer from the above-mentioned bug. Issue: SPR-8639
- Loading branch information
Showing
17 changed files
with
111 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
package org.springframework.issues; | ||
|
||
|
||
public class A implements IA { | ||
public class A { | ||
|
||
@SuppressWarnings("unused") | ||
private IC c; | ||
@SuppressWarnings("unused") | ||
private ICWithAutoWired cWithAutoWired; | ||
|
||
public void setC( IC c ) { | ||
this.c = c; | ||
public void setC(C c) { | ||
} | ||
|
||
public void setcWithAutoWired( ICWithAutoWired cWithAutoWired ) { | ||
this.cWithAutoWired = cWithAutoWired; | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
SPR-8639/src/main/java/org/springframework/issues/AnyInterceptor.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
package org.springframework.issues; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class C implements IC { | ||
public class C { | ||
|
||
private D d; | ||
@Autowired D d; | ||
|
||
public void setD( D d ) { | ||
this.d = d; | ||
} | ||
|
||
public D getD() { | ||
return d; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
SPR-8639/src/main/java/org/springframework/issues/CWithAutoWired.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
SPR-8639/src/main/java/org/springframework/issues/ICWithAutoWired.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
SPR-8639/src/main/java/org/springframework/issues/MyInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.springframework.issues; | ||
|
||
import org.aopalliance.intercept.MethodInterceptor; | ||
import org.aopalliance.intercept.MethodInvocation; | ||
|
||
public class MyInterceptor implements MethodInterceptor { | ||
|
||
public Object invoke(MethodInvocation invocation) throws Throwable { | ||
return invocation.proceed(); | ||
} | ||
|
||
} |
36 changes: 0 additions & 36 deletions
36
SPR-8639/src/test/java/org/springframework/issues/InterceptorTests.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
SPR-8639/src/test/java/org/springframework/issues/ReproTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.springframework.issues; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.springframework.aop.Advisor; | ||
import org.springframework.aop.framework.Advised; | ||
import org.springframework.aop.support.AopUtils; | ||
import org.springframework.context.support.GenericXmlApplicationContext; | ||
|
||
public class ReproTests { | ||
|
||
@Test | ||
public void repro() throws Exception { | ||
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); | ||
ctx.load(getClass(), "ReproTests-context.xml"); | ||
ctx.refresh(); | ||
|
||
C c = ctx.getBean(C.class); | ||
MyInterceptor interceptor = ctx.getBean(MyInterceptor.class); | ||
|
||
assertThat("expected c to be a proxy", AopUtils.isAopProxy(c), is(true)); | ||
Advisor[] advisors = ((Advised)c).getAdvisors(); | ||
assertTrue("interceptor was not added to c's set of advisors", | ||
advisors.length == 1 && advisors[0].getAdvice() == interceptor); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
|
||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<!-- Appenders --> | ||
<appender name="console" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%-5p: %c - %m%n" /> | ||
</layout> | ||
</appender> | ||
|
||
<logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory"> | ||
<level value="debug" /> | ||
</logger> | ||
<logger name="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"> | ||
<level value="debug" /> | ||
</logger> | ||
|
||
<!-- Root Logger --> | ||
<root> | ||
<priority value="warn" /> | ||
<appender-ref ref="console" /> | ||
</root> | ||
|
||
</log4j:configuration> |
30 changes: 30 additions & 0 deletions
30
SPR-8639/src/test/resources/org/springframework/issues/ReproTests-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> | ||
|
||
<context:annotation-config/> | ||
|
||
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> | ||
<property name="interceptorNames" value="myInterceptor"/> | ||
<property name="beanNames" value="a,b,c"/> | ||
</bean> | ||
|
||
<bean id="myInterceptor" class="org.springframework.issues.MyInterceptor"/> | ||
|
||
<bean id="a" class="org.springframework.issues.A"> | ||
<property name="c" ref="c"/> | ||
</bean> | ||
|
||
<bean id="b" class="org.springframework.issues.B"> | ||
<property name="c" ref="c"/> | ||
</bean> | ||
|
||
<bean id="c" class="org.springframework.issues.C"/> | ||
|
||
<!-- will be @Autowired into C --> | ||
<bean id="d" class="org.springframework.issues.D"/> | ||
|
||
</beans> |
56 changes: 0 additions & 56 deletions
56
SPR-8639/src/test/resources/org/springframework/issues/app-test-context.xml
This file was deleted.
Oops, something went wrong.