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

Commit 4928f52

Browse files
committed
Merge pull request #152 from molindo:spr-15384
* pr/152: Add repro project for SPR-15384
2 parents 337ce3c + d447102 commit 4928f52

File tree

7 files changed

+191
-0
lines changed

7 files changed

+191
-0
lines changed

SPR-15384/pom.xml

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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-15384</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
12+
<java.version>1.6</java.version>
13+
<spring.version>4.3.5.RELEASE</spring.version>
14+
<slf4j.version>1.7.22</slf4j.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-context</artifactId>
21+
<version>${spring.version}</version>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.slf4j</groupId>
26+
<artifactId>slf4j-api</artifactId>
27+
<version>${slf4j.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.slf4j</groupId>
31+
<artifactId>slf4j-log4j12</artifactId>
32+
<version>${slf4j.version}</version>
33+
<scope>runtime</scope>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<version>4.12</version>
40+
<scope>test</scope>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-compiler-plugin</artifactId>
49+
<version>2.5.1</version>
50+
<configuration>
51+
<source>${java.version}</source>
52+
<target>${java.version}</target>
53+
</configuration>
54+
</plugin>
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-surefire-plugin</artifactId>
58+
<version>2.12.4</version>
59+
<configuration>
60+
<includes>
61+
<include>**/*Tests.java</include>
62+
<include>**/*Test.java</include>
63+
</includes>
64+
<excludes>
65+
<exclude>**/*Abstract*.java</exclude>
66+
</excludes>
67+
</configuration>
68+
</plugin>
69+
</plugins>
70+
</build>
71+
72+
<repositories>
73+
<repository>
74+
<id>spring-maven-snapshot</id>
75+
<name>Springframework Maven Snapshot Repository</name>
76+
<url>http://repo.spring.io/snapshot</url>
77+
<snapshots>
78+
<enabled>true</enabled>
79+
</snapshots>
80+
</repository>
81+
</repositories>
82+
83+
</project>
84+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.springframework.issues;
2+
3+
public class Bar {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.springframework.issues;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ConditionContext;
5+
import org.springframework.context.annotation.Conditional;
6+
import org.springframework.context.annotation.Configuration;
7+
import org.springframework.context.annotation.ConfigurationCondition;
8+
import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase;
9+
import org.springframework.core.Ordered;
10+
import org.springframework.core.annotation.Order;
11+
import org.springframework.core.type.AnnotatedTypeMetadata;
12+
13+
@Configuration
14+
public class Config {
15+
16+
public static final String BEAN_NAME = "name";
17+
18+
@Order(Ordered.HIGHEST_PRECEDENCE)
19+
@Conditional(OnBeanMissingCondition.class)
20+
public class MemberBefore {
21+
22+
@Bean(BEAN_NAME)
23+
public Foo foo() {
24+
return new Foo();
25+
}
26+
27+
}
28+
29+
@Order(Ordered.LOWEST_PRECEDENCE)
30+
@Conditional(OnBeanMissingCondition.class)
31+
public class MemberAfter {
32+
33+
@Bean(BEAN_NAME)
34+
public Bar bar() {
35+
return new Bar();
36+
}
37+
38+
}
39+
40+
// based on org.springframework.boot.autoconfigure.condition.OnBeanCondition
41+
public static class OnBeanMissingCondition implements ConfigurationCondition {
42+
43+
44+
@Override
45+
public ConfigurationPhase getConfigurationPhase() {
46+
return ConfigurationPhase.REGISTER_BEAN;
47+
}
48+
49+
@Override
50+
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
51+
return !context.getBeanFactory().containsBeanDefinition(BEAN_NAME);
52+
}
53+
54+
}
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.springframework.issues;
2+
3+
public class Foo {
4+
5+
}

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

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.springframework.issues;
2+
3+
import static org.hamcrest.CoreMatchers.*;
4+
import static org.junit.Assert.*;
5+
6+
import org.hamcrest.CoreMatchers;
7+
import org.junit.Test;
8+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
9+
import org.springframework.context.support.GenericXmlApplicationContext;
10+
11+
/**
12+
* Unit test that reproduces <a href="https://jira.spring.io/browse/SPR-15384">SPR-15384</a>
13+
*/
14+
public class ReproTests {
15+
16+
17+
/**
18+
* if member classes are ordered, an instance of class {@link Foo} should be added with name "test".
19+
* If members are ordered alphabetically, it will be of class {@link Bar}
20+
*/
21+
@Test
22+
public void repro() {
23+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
24+
ctx.register(Config.class);
25+
ctx.refresh();
26+
27+
Object test = ctx.getBean(Config.BEAN_NAME);
28+
29+
assertThat(test, is(instanceOf(Foo.class)));
30+
31+
ctx.close();
32+
}
33+
34+
}
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

0 commit comments

Comments
 (0)