Merge branch 'main' into 4.0.x
This commit is contained in:
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.Binder;
|
||||||
import org.springframework.boot.context.properties.bind.PlaceholdersResolver;
|
import org.springframework.boot.context.properties.bind.PlaceholdersResolver;
|
||||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
||||||
|
import org.springframework.boot.origin.OriginLookup;
|
||||||
import org.springframework.core.convert.ConversionService;
|
import org.springframework.core.convert.ConversionService;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
@@ -414,7 +415,7 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
|
|||||||
static ConfigDataEnvironmentContributor ofExisting(PropertySource<?> propertySource,
|
static ConfigDataEnvironmentContributor ofExisting(PropertySource<?> propertySource,
|
||||||
ConversionService conversionService) {
|
ConversionService conversionService) {
|
||||||
return new ConfigDataEnvironmentContributor(Kind.EXISTING, null, null, false, propertySource,
|
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<ConfigDataEnvironment
|
|||||||
ConversionService conversionService) {
|
ConversionService conversionService) {
|
||||||
PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
|
PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
|
||||||
ConfigData.Options options = configData.getOptions(propertySource);
|
ConfigData.Options options = configData.getOptions(propertySource);
|
||||||
ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(propertySource);
|
|
||||||
return new ConfigDataEnvironmentContributor(Kind.UNBOUND_IMPORT, location, resource, profileSpecific,
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.io.TempDir;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.TestApplicationEnvironment;
|
||||||
import org.springframework.boot.WebApplicationType;
|
import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.context.properties.bind.BindContext;
|
import org.springframework.boot.context.properties.bind.BindContext;
|
||||||
import org.springframework.boot.context.properties.bind.BindException;
|
import org.springframework.boot.context.properties.bind.BindException;
|
||||||
@@ -461,6 +462,21 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
|
|||||||
assertThat(context.getEnvironment().getProperty("my.property")).isEqualTo("fromotherpropertiesfile");
|
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<String, Object> getSystemEnvironment() {
|
||||||
|
return Map.of("EXAMPLE_PREFIX_SPRING_PROFILES_ACTIVE", "other,dev");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
ConfigurableApplicationContext context = this.application.run();
|
||||||
|
assertThat(context.getEnvironment().getActiveProfiles()).contains("dev", "other");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@WithResource(name = "application.yaml", content = """
|
@WithResource(name = "application.yaml", content = """
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in New Issue
Block a user