From e1ff4fbaf99bfcfdf0828ed07664b208a3ca6157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 14 May 2025 12:38:43 +0200 Subject: [PATCH 1/2] Upgrade to Jackson Bom 2.19.0 Closes gh-45542 --- gradle.properties | 2 +- spring-boot-project/spring-boot-dependencies/build.gradle | 5 ++++- .../buildpack/platform/build/BuildpackLayersMetadata.java | 8 ++++---- .../boot/buildpack/platform/json/MappedObject.java | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1e7c54029b..51d11f10a1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ checkstyleToolVersion=10.12.4 commonsCodecVersion=1.18.0 graalVersion=22.3 hamcrestVersion=3.0 -jacksonVersion=2.18.4 +jacksonVersion=2.19.0 javaFormatVersion=0.0.43 junitJupiterVersion=5.12.2 kotlinVersion=1.9.25 diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 22320f552a..4cb2e6522b 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -692,7 +692,10 @@ bom { because "we don't want release candidates" } group("com.fasterxml.jackson") { - bom("jackson-bom") + bom("jackson-bom") { + permit("com.fasterxml.woodstox:woodstox-core") + permit("org.codehaus.woodstox:stax2-api") + } } links { releaseNotes("https://github.com/FasterXML/jackson/wiki/Jackson-Release-{version}") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java index ac9f54591e..eadb2c391e 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadata.java @@ -118,8 +118,8 @@ final class BuildpackLayersMetadata extends MappedObject { private static Buildpacks fromJson(JsonNode node) { Buildpacks buildpacks = new Buildpacks(); - node.fields() - .forEachRemaining((field) -> buildpacks.addBuildpackVersions(field.getKey(), + node.properties() + .forEach((field) -> buildpacks.addBuildpackVersions(field.getKey(), BuildpackVersions.fromJson(field.getValue()))); return buildpacks; } @@ -140,8 +140,8 @@ final class BuildpackLayersMetadata extends MappedObject { private static BuildpackVersions fromJson(JsonNode node) { BuildpackVersions versions = new BuildpackVersions(); - node.fields() - .forEachRemaining((field) -> versions.addBuildpackVersion(field.getKey(), + node.properties() + .forEach((field) -> versions.addBuildpackVersion(field.getKey(), BuildpackLayerDetails.fromJson(field.getValue()))); return versions; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java index 936e57bfe8..26b8b1a30b 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/json/MappedObject.java @@ -90,8 +90,8 @@ public class MappedObject { protected Map mapAt(String expression, Function valueMapper) { Map map = new LinkedHashMap<>(); getNode().at(expression) - .fields() - .forEachRemaining((entry) -> map.put(entry.getKey(), valueMapper.apply(entry.getValue()))); + .properties() + .forEach((entry) -> map.put(entry.getKey(), valueMapper.apply(entry.getValue()))); return Collections.unmodifiableMap(map); } From ce900b1304d268ef8d50049e99722a6f1a87eef0 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 14 May 2025 15:23:49 -0700 Subject: [PATCH 2/2] Ensure setEnvironmentPrefix works with spring.profiles.active Update `ConfigDataEnvironmentContributor` to ensure that origin prefixes are considered when binding properties. Fixes gh-45387 --- .../ConfigDataEnvironmentContributor.java | 16 +++++++++--- .../boot/TestApplicationEnvironment.java | 26 +++++++++++++++++++ ...ironmentPostProcessorIntegrationTests.java | 16 ++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 spring-boot-project/spring-boot/src/test/java/org/springframework/boot/TestApplicationEnvironment.java diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java index 4d74198c1e..1822947978 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 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. @@ -29,6 +29,7 @@ import java.util.stream.StreamSupport; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.bind.PlaceholdersResolver; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; +import org.springframework.boot.origin.OriginLookup; import org.springframework.core.convert.ConversionService; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertySource; @@ -414,7 +415,7 @@ class ConfigDataEnvironmentContributor implements Iterable propertySource, ConversionService conversionService) { return new ConfigDataEnvironmentContributor(Kind.EXISTING, null, null, false, propertySource, - ConfigurationPropertySource.from(propertySource), null, null, null, conversionService); + asConfigurationPropertySource(propertySource), null, null, null, conversionService); } /** @@ -434,9 +435,16 @@ class ConfigDataEnvironmentContributor implements Iterable propertySource = configData.getPropertySources().get(propertySourceIndex); ConfigData.Options options = configData.getOptions(propertySource); - ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(propertySource); return new ConfigDataEnvironmentContributor(Kind.UNBOUND_IMPORT, location, resource, profileSpecific, - propertySource, configurationPropertySource, null, options, null, conversionService); + propertySource, asConfigurationPropertySource(propertySource), null, options, null, conversionService); + } + + private static ConfigurationPropertySource asConfigurationPropertySource(PropertySource propertySource) { + ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(propertySource); + if (configurationPropertySource != null && propertySource instanceof OriginLookup originLookup) { + configurationPropertySource = configurationPropertySource.withPrefix(originLookup.getPrefix()); + } + return configurationPropertySource; } /** diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/TestApplicationEnvironment.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/TestApplicationEnvironment.java new file mode 100644 index 0000000000..62868352d3 --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/TestApplicationEnvironment.java @@ -0,0 +1,26 @@ +/* + * Copyright 2012-2025 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot; + +/** + * Public version {@link ApplicationEnvironment} for tests to use. + * + * @author Phillip Webb + */ +public class TestApplicationEnvironment extends ApplicationEnvironment { + +} diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java index 12005f44db..0b1c19ba41 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java @@ -38,6 +38,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.springframework.boot.SpringApplication; +import org.springframework.boot.TestApplicationEnvironment; import org.springframework.boot.WebApplicationType; import org.springframework.boot.context.properties.bind.BindContext; import org.springframework.boot.context.properties.bind.BindException; @@ -461,6 +462,21 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests { assertThat(context.getEnvironment().getProperty("my.property")).isEqualTo("fromotherpropertiesfile"); } + @Test // gh-45387 + void runWhenProfileActivatedViaSystemEnvironmentVariableWithPrefix() { + this.application.setEnvironmentPrefix("example.prefix"); + this.application.setEnvironment(new TestApplicationEnvironment() { + + @Override + public Map getSystemEnvironment() { + return Map.of("EXAMPLE_PREFIX_SPRING_PROFILES_ACTIVE", "other,dev"); + } + + }); + ConfigurableApplicationContext context = this.application.run(); + assertThat(context.getEnvironment().getActiveProfiles()).contains("dev", "other"); + } + @Test @WithResource(name = "application.yaml", content = """ ---