From a7876333d3ac83963a69df69654c9b2e2ee374dc Mon Sep 17 00:00:00 2001 From: Maurice Zeijen Date: Thu, 12 Oct 2023 21:35:01 +0200 Subject: [PATCH] Fixed order of the `BootstrapConfigFileApplicationListener` so that it always runs after the `ConfigDataEnvironmentPostProcessor` (#1213) * Changed order of `BootstrapConfigFileApplicationListener` Previously `BootstrapConfigFileApplicationListener` had the same order as `ConfigDataEnvironmentPostProcessor`. This made it indeterminable which one would run first. However, the `BootstrapConfigFileApplicationListener` relies on the `ConfigDataEnvironmentPostProcessor` to make sure the `Environment.activeProfiles` are correctly set, so it must always run after the `ConfigDataEnvironmentPostProcessor`. * Using `Math.addExact` for adding one to the `ConfigDataEnvironmentPostProcessor.DEFAULT_ORDER` so that any accidental overflow results in an exception --- .../bootstrap/BootstrapConfigFileApplicationListener.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapConfigFileApplicationListener.java b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapConfigFileApplicationListener.java index 323643ac..03c9893a 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapConfigFileApplicationListener.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/bootstrap/BootstrapConfigFileApplicationListener.java @@ -166,7 +166,10 @@ public class BootstrapConfigFileApplicationListener /** * The default order for the processor. */ - public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10; + public static final int DEFAULT_ORDER = + // This listener needs to run after the `ConfigDataEnvironmentPostProcessor` to + // make sure the `Environment.activeProfiles` are correctly set + Math.addExact(ConfigDataEnvironmentPostProcessor.ORDER, 1); private final Log logger;