Make sure bootstrap sources are ordered before use.
Make call to sort() before setting on builder.sources(). fixes gh-176
This commit is contained in:
@@ -133,8 +133,8 @@ public class BootstrapApplicationListener
|
|||||||
}
|
}
|
||||||
sources.add(cls);
|
sources.add(cls);
|
||||||
}
|
}
|
||||||
builder.sources(sources.toArray(new Class[sources.size()]));
|
|
||||||
AnnotationAwareOrderComparator.sort(sources);
|
AnnotationAwareOrderComparator.sort(sources);
|
||||||
|
builder.sources(sources.toArray(new Class[sources.size()]));
|
||||||
final ConfigurableApplicationContext context = builder.run();
|
final ConfigurableApplicationContext context = builder.run();
|
||||||
// Make the bootstrap context a parent of the app context
|
// Make the bootstrap context a parent of the app context
|
||||||
addAncestorInitializer(application, context);
|
addAncestorInitializer(application, context);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.springframework.cloud.bootstrap;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.cloud.bootstrap.BootstrapOrderingSpringApplicationJsonIntegrationTests.Application;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = Application.class)
|
||||||
|
public class BootstrapSourcesOrderingTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConfigurableEnvironment environment;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sourcesAreOrderedCorrectly() {
|
||||||
|
Class<?> firstConstructedClass = firstToBeCreated.get();
|
||||||
|
assertThat(firstConstructedClass).as("bootstrap sources not ordered correctly").isEqualTo(TestHigherPriorityBootstrapConfiguration.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EnableAutoConfiguration
|
||||||
|
@Configuration
|
||||||
|
protected static class Application {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.springframework.cloud.bootstrap;
|
||||||
|
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
import static org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration.firstToBeCreated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Spencer Gibb
|
||||||
|
*/
|
||||||
|
@Order(0)
|
||||||
|
public class TestBootstrapConfiguration {
|
||||||
|
|
||||||
|
public TestBootstrapConfiguration() {
|
||||||
|
firstToBeCreated.compareAndSet(null, TestBootstrapConfiguration.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.springframework.cloud.bootstrap;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Spencer Gibb
|
||||||
|
*/
|
||||||
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||||
|
public class TestHigherPriorityBootstrapConfiguration {
|
||||||
|
|
||||||
|
static final AtomicReference<Class<?>> firstToBeCreated = new AtomicReference<>();
|
||||||
|
|
||||||
|
public TestHigherPriorityBootstrapConfiguration() {
|
||||||
|
firstToBeCreated.compareAndSet(null, TestHigherPriorityBootstrapConfiguration.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Bootstrap components
|
||||||
|
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||||
|
org.springframework.cloud.bootstrap.TestBootstrapConfiguration,\
|
||||||
|
org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration
|
||||||
Reference in New Issue
Block a user