File tree Expand file tree Collapse file tree 5 files changed +76
-1
lines changed
main/java/org/springframework/cloud/bootstrap
java/org/springframework/cloud/bootstrap Expand file tree Collapse file tree 5 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -133,8 +133,8 @@ private ConfigurableApplicationContext bootstrapServiceContext(
133
133
}
134
134
sources .add (cls );
135
135
}
136
- builder .sources (sources .toArray (new Class [sources .size ()]));
137
136
AnnotationAwareOrderComparator .sort (sources );
137
+ builder .sources (sources .toArray (new Class [sources .size ()]));
138
138
final ConfigurableApplicationContext context = builder .run ();
139
139
// Make the bootstrap context a parent of the app context
140
140
addAncestorInitializer (application , context );
Original file line number Diff line number Diff line change
1
+ package org .springframework .cloud .bootstrap ;
2
+
3
+ import org .junit .Test ;
4
+ import org .junit .runner .RunWith ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
7
+ import org .springframework .boot .test .context .SpringBootTest ;
8
+ import org .springframework .cloud .bootstrap .BootstrapOrderingSpringApplicationJsonIntegrationTests .Application ;
9
+ import org .springframework .context .annotation .Configuration ;
10
+ import org .springframework .core .env .ConfigurableEnvironment ;
11
+ import org .springframework .test .context .junit4 .SpringRunner ;
12
+
13
+ import static org .assertj .core .api .Assertions .assertThat ;
14
+ import static org .springframework .cloud .bootstrap .TestHigherPriorityBootstrapConfiguration .firstToBeCreated ;
15
+
16
+ @ RunWith (SpringRunner .class )
17
+ @ SpringBootTest (classes = Application .class )
18
+ public class BootstrapSourcesOrderingTests {
19
+
20
+ @ Autowired
21
+ private ConfigurableEnvironment environment ;
22
+
23
+ @ Test
24
+ public void sourcesAreOrderedCorrectly () {
25
+ Class <?> firstConstructedClass = firstToBeCreated .get ();
26
+ assertThat (firstConstructedClass ).as ("bootstrap sources not ordered correctly" ).isEqualTo (TestHigherPriorityBootstrapConfiguration .class );
27
+ }
28
+
29
+ @ EnableAutoConfiguration
30
+ @ Configuration
31
+ protected static class Application {
32
+ }
33
+
34
+ }
Original file line number Diff line number Diff line change
1
+ package org .springframework .cloud .bootstrap ;
2
+
3
+ import org .springframework .core .annotation .Order ;
4
+
5
+ import static org .springframework .cloud .bootstrap .TestHigherPriorityBootstrapConfiguration .firstToBeCreated ;
6
+
7
+ /**
8
+ * @author Spencer Gibb
9
+ */
10
+ @ Order (0 )
11
+ public class TestBootstrapConfiguration {
12
+
13
+ public TestBootstrapConfiguration () {
14
+ firstToBeCreated .compareAndSet (null , TestBootstrapConfiguration .class );
15
+ }
16
+
17
+ }
Original file line number Diff line number Diff line change
1
+ package org .springframework .cloud .bootstrap ;
2
+
3
+ import java .util .concurrent .atomic .AtomicReference ;
4
+
5
+ import org .springframework .core .Ordered ;
6
+ import org .springframework .core .annotation .Order ;
7
+
8
+ /**
9
+ * @author Spencer Gibb
10
+ */
11
+ @ Order (Ordered .HIGHEST_PRECEDENCE )
12
+ public class TestHigherPriorityBootstrapConfiguration {
13
+
14
+ static final AtomicReference <Class <?>> firstToBeCreated = new AtomicReference <>();
15
+
16
+ public TestHigherPriorityBootstrapConfiguration () {
17
+ firstToBeCreated .compareAndSet (null , TestHigherPriorityBootstrapConfiguration .class );
18
+ }
19
+
20
+ }
Original file line number Diff line number Diff line change
1
+ # Bootstrap components
2
+ org.springframework.cloud.bootstrap.BootstrapConfiguration=\
3
+ org.springframework.cloud.bootstrap.TestBootstrapConfiguration,\
4
+ org.springframework.cloud.bootstrap.TestHigherPriorityBootstrapConfiguration
You can’t perform that action at this time.
0 commit comments