Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 9287460

Browse files
committed
Merge pull request #22 from barni/SPR-9181
* SPR-9181: Add repro project for SPR-9181
2 parents 88f748a + a696df3 commit 9287460

File tree

10 files changed

+204
-0
lines changed

10 files changed

+204
-0
lines changed

SPR-9181/pom.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-9181</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<dependencies>
9+
<dependency>
10+
<groupId>org.springframework</groupId>
11+
<artifactId>spring-context</artifactId>
12+
<!-- Fails
13+
<version>3.2.0.BUILD-SNAPSHOT</version>
14+
-->
15+
<version>3.1.1.RELEASE</version>
16+
<!-- Works
17+
<version>3.1.0.RELEASE</version>
18+
-->
19+
</dependency>
20+
<dependency>
21+
<groupId>log4j</groupId>
22+
<artifactId>log4j</artifactId>
23+
<version>1.2.16</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>javax.inject</groupId>
27+
<artifactId>javax.inject</artifactId>
28+
<version>1</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>junit</groupId>
32+
<artifactId>junit</artifactId>
33+
<version>4.8</version>
34+
<scope>test</scope>
35+
</dependency>
36+
</dependencies>
37+
<repositories>
38+
<repository>
39+
<id>springsource</id>
40+
<name>SpringSource Repository</name>
41+
<url>http://repo.springsource.org/snapshot</url>
42+
<snapshots><enabled>true</enabled></snapshots>
43+
</repository>
44+
</repositories>
45+
<properties>
46+
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
47+
</properties>
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<artifactId>maven-compiler-plugin</artifactId>
52+
<version>2.3.2</version>
53+
<configuration>
54+
<source>1.6</source>
55+
<target>1.6</target>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-surefire-plugin</artifactId>
60+
<version>2.7.2</version>
61+
<configuration>
62+
<includes>
63+
<include>**/*Tests.java</include>
64+
</includes>
65+
<excludes>
66+
<exclude>**/*Abstract*.java</exclude>
67+
</excludes>
68+
</configuration>
69+
</plugin>
70+
</plugins>
71+
</build>
72+
</project>
73+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.context.annotation.Scope;
4+
5+
import javax.inject.Inject;
6+
import javax.inject.Named;
7+
8+
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
9+
10+
@Named
11+
@Scope(SCOPE_PROTOTYPE)
12+
public class Bar {
13+
14+
Foo foo;
15+
16+
@Inject
17+
public Bar(@Named("testFactory") Foo foo){
18+
this.foo = foo;
19+
}
20+
21+
public Foo getFoo(){
22+
return foo;
23+
}
24+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Lazy;
5+
import org.springframework.context.annotation.Scope;
6+
7+
import javax.inject.Named;
8+
import javax.inject.Provider;
9+
10+
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
11+
12+
@Named
13+
@Lazy(false)
14+
public class Factory {
15+
@Bean
16+
@Scope(SCOPE_PROTOTYPE)
17+
public Foo testFactory(final Provider<ProviderClass> testProvider) {
18+
return new Foo(testProvider);
19+
}
20+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.springframework.issues;
2+
3+
import javax.inject.Provider;
4+
5+
6+
public class Foo {
7+
8+
Provider<ProviderClass> testProvider;
9+
10+
public Foo(Provider<ProviderClass> testProvider) {
11+
this.testProvider = testProvider;
12+
}
13+
14+
public ProviderClass getProviderClass(){
15+
return testProvider.get();
16+
}
17+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.springframework.issues;
2+
3+
public interface ProviderClass {
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.context.annotation.Scope;
4+
5+
import javax.inject.Named;
6+
7+
import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;
8+
9+
@Named
10+
@Scope(SCOPE_PROTOTYPE)
11+
public class ProviderClassImpl implements ProviderClass {
12+
13+
public ProviderClassImpl(){
14+
15+
}
16+
}

SPR-9181/src/main/resources/.gitignore

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.springframework.issues;
2+
3+
import org.junit.Test;
4+
import org.springframework.context.support.GenericXmlApplicationContext;
5+
6+
/**
7+
* Unit test that reproduces an issue reported against SPR JIRA. @Test methods within
8+
* need not pass with the green bar! Rather they should fail in such a way that
9+
* demonstrates the reported issue.
10+
*/
11+
public class ReproTests {
12+
13+
@Test
14+
public void repro() {
15+
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
16+
ctx.load("classpath:org/springframework/issues/ReproTests-context.xml");
17+
ctx.refresh();
18+
19+
// First time works
20+
Bar bar = ctx.getBean(Bar.class);
21+
bar.getFoo().getProviderClass();
22+
23+
// Second call crashes
24+
bar = ctx.getBean(Bar.class);
25+
bar.getFoo().getProviderClass();
26+
}
27+
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootCategory=ERROR, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
6+
7+
log4j.category.org.springframework=WARN
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:aop="http://www.springframework.org/schema/aop"
4+
xmlns:tx="http://www.springframework.org/schema/tx"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
8+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
9+
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
10+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
11+
default-lazy-init="true">
12+
13+
<context:component-scan base-package="org.springframework.issues"/>
14+
15+
</beans>

0 commit comments

Comments
 (0)