From b1e8d6a08c920a6b263d0effc993f7cf07207318 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Thu, 8 Feb 2024 14:35:20 +0100 Subject: [PATCH] Fix the order in which the postprocessors run. (#1333) --- .../client/HostInfoEnvironmentPostProcessor.java | 11 +++++++---- .../BootstrapConfigFileApplicationListener.java | 11 ++++++----- .../core/SubsetServiceInstanceListSupplierTest.java | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java index e44d4364..c5e32226 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/client/HostInfoEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.cloud.client; import java.util.LinkedHashMap; import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor; import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySources; @@ -32,15 +33,17 @@ import org.springframework.core.env.MapPropertySource; /** * @author Spencer Gibb + * @author Olga Maciaszek-Sharma */ public class HostInfoEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { - // Before BootstrapConfigFileApplicationListener - private int order = Ordered.HIGHEST_PRECEDENCE + 9; + // Before BootstrapConfigFileApplicationListener, but after + // ConfigDataEnvironmentPostProcessor + private static final int ORDER = Math.addExact(ConfigDataEnvironmentPostProcessor.ORDER, 1); @Override public int getOrder() { - return this.order; + return ORDER; } @Override 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 74a37f3b..9c412dfb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ import org.springframework.util.StringUtils; /** * {@link EnvironmentPostProcessor} that configures the context environment by loading - * properties from well known file locations. By default properties will be loaded from + * properties from well known file locations. By default, properties will be loaded from * 'application.properties' and/or 'application.yml' files in the following locations: *