Skip to content

Commit e2f5175

Browse files
committed
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
1 parent 876f756 commit e2f5175

File tree

17 files changed

+111
-196
lines changed

17 files changed

+111
-196
lines changed

SPR-8639/pom.xml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99
<dependency>
1010
<groupId>org.springframework</groupId>
1111
<artifactId>spring-context</artifactId>
12-
<!-- <version>3.1.0.BUILD-SNAPSHOT</version> -->
13-
<version>3.0.5.RELEASE</version>
14-
</dependency>
15-
<dependency>
16-
<groupId>org.springframework</groupId>
17-
<artifactId>spring-test</artifactId>
18-
<!-- <version>3.1.0.BUILD-SNAPSHOT</version> -->
19-
<version>3.0.5.RELEASE</version>
20-
<scope>test</scope>
12+
<version>3.1.0.BUILD-SNAPSHOT</version>
2113
</dependency>
2214
<dependency>
2315
<groupId>junit</groupId>
2416
<artifactId>junit</artifactId>
2517
<version>4.8</version>
2618
<scope>test</scope>
2719
</dependency>
20+
<dependency>
21+
<groupId>cglib</groupId>
22+
<artifactId>cglib-nodep</artifactId>
23+
<version>2.2</version>
24+
<scope>test</scope>
25+
</dependency>
2826
<dependency>
2927
<groupId>log4j</groupId>
3028
<artifactId>log4j</artifactId>
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
package org.springframework.issues;
22

33

4-
public class A implements IA {
4+
public class A {
55

6-
@SuppressWarnings("unused")
7-
private IC c;
8-
@SuppressWarnings("unused")
9-
private ICWithAutoWired cWithAutoWired;
10-
11-
public void setC( IC c ) {
12-
this.c = c;
6+
public void setC(C c) {
137
}
148

15-
public void setcWithAutoWired( ICWithAutoWired cWithAutoWired ) {
16-
this.cWithAutoWired = cWithAutoWired;
17-
}
189
}

SPR-8639/src/main/java/org/springframework/issues/AnyInterceptor.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

SPR-8639/src/main/java/org/springframework/issues/B.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@
33

44
public class B {
55

6-
@SuppressWarnings("unused")
7-
private IC c;
8-
@SuppressWarnings("unused")
9-
private ICWithAutoWired cWithAutoWired;
10-
11-
public void setC( IC c ) {
12-
this.c = c;
6+
public void setC(C c) {
137
}
148

15-
public void setCWithAutoWired( ICWithAutoWired cWithAutoWired ) {
16-
this.cWithAutoWired = cWithAutoWired;
17-
}
189
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
package org.springframework.issues;
22

3+
import org.springframework.beans.factory.annotation.Autowired;
34

4-
public class C implements IC {
5+
public class C {
56

6-
private D d;
7+
@Autowired D d;
78

8-
public void setD( D d ) {
9-
this.d = d;
10-
}
11-
12-
public D getD() {
13-
return d;
14-
}
159
}

SPR-8639/src/main/java/org/springframework/issues/CWithAutoWired.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

SPR-8639/src/main/java/org/springframework/issues/IA.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

SPR-8639/src/main/java/org/springframework/issues/IB.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

SPR-8639/src/main/java/org/springframework/issues/IC.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

SPR-8639/src/main/java/org/springframework/issues/ICWithAutoWired.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)