Skip to content

Commit b1e8d6a

Browse files
Fix the order in which the postprocessors run. (#1333)
1 parent a292134 commit b1e8d6a

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.util.LinkedHashMap;
2020

2121
import org.springframework.boot.SpringApplication;
22+
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
2223
import org.springframework.boot.context.properties.bind.Bindable;
2324
import org.springframework.boot.context.properties.bind.Binder;
2425
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
@@ -32,15 +33,17 @@
3233

3334
/**
3435
* @author Spencer Gibb
36+
* @author Olga Maciaszek-Sharma
3537
*/
3638
public class HostInfoEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
3739

38-
// Before BootstrapConfigFileApplicationListener
39-
private int order = Ordered.HIGHEST_PRECEDENCE + 9;
40+
// Before BootstrapConfigFileApplicationListener, but after
41+
// ConfigDataEnvironmentPostProcessor
42+
private static final int ORDER = Math.addExact(ConfigDataEnvironmentPostProcessor.ORDER, 1);
4043

4144
@Override
4245
public int getOrder() {
43-
return this.order;
46+
return ORDER;
4447
}
4548

4649
@Override

spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapConfigFileApplicationListener.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2020 the original author or authors.
2+
* Copyright 2013-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,7 +85,7 @@
8585

8686
/**
8787
* {@link EnvironmentPostProcessor} that configures the context environment by loading
88-
* properties from well known file locations. By default properties will be loaded from
88+
* properties from well known file locations. By default, properties will be loaded from
8989
* 'application.properties' and/or 'application.yml' files in the following locations:
9090
* <ul>
9191
* <li>file:./config/</li>
@@ -116,6 +116,7 @@
116116
* @author Eddú Meléndez
117117
* @author Madhura Bhave
118118
* @author Scott Frederick
119+
* @author Olga Maciaszek-Sharma
119120
* @since 1.0.0 {@link ConfigDataEnvironmentPostProcessor}
120121
*/
121122
public class BootstrapConfigFileApplicationListener
@@ -168,9 +169,9 @@ public class BootstrapConfigFileApplicationListener
168169
*/
169170
public static final int DEFAULT_ORDER =
170171
// This listener needs to run after the `ConfigDataEnvironmentPostProcessor`
171-
// to
172-
// make sure the `Environment.activeProfiles` are correctly set
173-
Math.addExact(ConfigDataEnvironmentPostProcessor.ORDER, 1);
172+
// and `HostInfoEnvironmentPostProcessor`
173+
// to make sure the `Environment.activeProfiles` are correctly set
174+
Math.addExact(ConfigDataEnvironmentPostProcessor.ORDER, 2);
174175

175176
private final Log logger;
176177

spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/SubsetServiceInstanceListSupplierTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@
4040
import static org.springframework.cloud.loadbalancer.core.LoadBalancerTestUtils.buildLoadBalancerClientFactory;
4141

4242
/**
43-
* Tests for {@link SubsetServiceInstanceListSupplier}
43+
* Tests for {@link SubsetServiceInstanceListSupplier}.
4444
*
4545
* @author Zhuozhi Ji
4646
*/

0 commit comments

Comments
 (0)