diff --git a/SPR-15384/pom.xml b/SPR-15384/pom.xml new file mode 100644 index 00000000..646980e7 --- /dev/null +++ b/SPR-15384/pom.xml @@ -0,0 +1,84 @@ + + 4.0.0 + org.springframework.issues + SPR-15384 + 1.0-SNAPSHOT + jar + + + UTF-8 + + 1.6 + 4.3.5.RELEASE + 1.7.22 + + + + + org.springframework + spring-context + ${spring.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + runtime + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + + **/*Tests.java + **/*Test.java + + + **/*Abstract*.java + + + + + + + + + spring-maven-snapshot + Springframework Maven Snapshot Repository + http://repo.spring.io/snapshot + + true + + + + + + diff --git a/SPR-15384/src/main/java/org/springframework/issues/Bar.java b/SPR-15384/src/main/java/org/springframework/issues/Bar.java new file mode 100644 index 00000000..2180bac3 --- /dev/null +++ b/SPR-15384/src/main/java/org/springframework/issues/Bar.java @@ -0,0 +1,5 @@ +package org.springframework.issues; + +public class Bar { + +} diff --git a/SPR-15384/src/main/java/org/springframework/issues/Config.java b/SPR-15384/src/main/java/org/springframework/issues/Config.java new file mode 100644 index 00000000..e3cb1863 --- /dev/null +++ b/SPR-15384/src/main/java/org/springframework/issues/Config.java @@ -0,0 +1,56 @@ +package org.springframework.issues; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ConfigurationCondition; +import org.springframework.context.annotation.ConfigurationCondition.ConfigurationPhase; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@Configuration +public class Config { + + public static final String BEAN_NAME = "name"; + + @Order(Ordered.HIGHEST_PRECEDENCE) + @Conditional(OnBeanMissingCondition.class) + public class MemberBefore { + + @Bean(BEAN_NAME) + public Foo foo() { + return new Foo(); + } + + } + + @Order(Ordered.LOWEST_PRECEDENCE) + @Conditional(OnBeanMissingCondition.class) + public class MemberAfter { + + @Bean(BEAN_NAME) + public Bar bar() { + return new Bar(); + } + + } + + // based on org.springframework.boot.autoconfigure.condition.OnBeanCondition + public static class OnBeanMissingCondition implements ConfigurationCondition { + + + @Override + public ConfigurationPhase getConfigurationPhase() { + return ConfigurationPhase.REGISTER_BEAN; + } + + @Override + public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { + return !context.getBeanFactory().containsBeanDefinition(BEAN_NAME); + } + + } + +} diff --git a/SPR-15384/src/main/java/org/springframework/issues/Foo.java b/SPR-15384/src/main/java/org/springframework/issues/Foo.java new file mode 100644 index 00000000..3119cb1d --- /dev/null +++ b/SPR-15384/src/main/java/org/springframework/issues/Foo.java @@ -0,0 +1,5 @@ +package org.springframework.issues; + +public class Foo { + +} diff --git a/SPR-15384/src/main/resources/.gitignore b/SPR-15384/src/main/resources/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/SPR-15384/src/test/java/org/springframework/issues/ReproTests.java b/SPR-15384/src/test/java/org/springframework/issues/ReproTests.java new file mode 100644 index 00000000..40fb6a46 --- /dev/null +++ b/SPR-15384/src/test/java/org/springframework/issues/ReproTests.java @@ -0,0 +1,34 @@ +package org.springframework.issues; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import org.hamcrest.CoreMatchers; +import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.GenericXmlApplicationContext; + +/** + * Unit test that reproduces SPR-15384 + */ +public class ReproTests { + + + /** + * if member classes are ordered, an instance of class {@link Foo} should be added with name "test". + * If members are ordered alphabetically, it will be of class {@link Bar} + */ + @Test + public void repro() { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + ctx.register(Config.class); + ctx.refresh(); + + Object test = ctx.getBean(Config.BEAN_NAME); + + assertThat(test, is(instanceOf(Foo.class))); + + ctx.close(); + } + +} diff --git a/SPR-15384/src/test/resources/log4j.properties b/SPR-15384/src/test/resources/log4j.properties new file mode 100644 index 00000000..82776b7b --- /dev/null +++ b/SPR-15384/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootCategory=ERROR, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n + +log4j.category.org.springframework=WARN \ No newline at end of file