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

Add repro project for SPR-15384 #152

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions SPR-15384/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.issues</groupId>
<artifactId>SPR-15384</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<java.version>1.6</java.version>
<spring.version>4.3.5.RELEASE</spring.version>
<slf4j.version>1.7.22</slf4j.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*Abstract*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-maven-snapshot</id>
<name>Springframework Maven Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

</project>

5 changes: 5 additions & 0 deletions SPR-15384/src/main/java/org/springframework/issues/Bar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.springframework.issues;

public class Bar {

}
56 changes: 56 additions & 0 deletions SPR-15384/src/main/java/org/springframework/issues/Config.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

}
5 changes: 5 additions & 0 deletions SPR-15384/src/main/java/org/springframework/issues/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.springframework.issues;

public class Foo {

}
Empty file.
34 changes: 34 additions & 0 deletions SPR-15384/src/test/java/org/springframework/issues/ReproTests.java
Original file line number Diff line number Diff line change
@@ -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 <a href="https://jira.spring.io/browse/SPR-15384">SPR-15384</a>
*/
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();
}

}
7 changes: 7 additions & 0 deletions SPR-15384/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -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