mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Support custom SpringBootContextLoader environment
Provide a `getEnvironment` method in `SpringBootContextLoader` to allow specialized `ConfigurableEnvironment` implementations to be used. Closes gh-10740
This commit is contained in:
parent
b58f1f00fa
commit
fae7a09b83
@ -105,7 +105,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
|
||||
application.setMainApplicationClass(config.getTestClass());
|
||||
application.addPrimarySources(Arrays.asList(configClasses));
|
||||
application.getSources().addAll(Arrays.asList(configLocations));
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
ConfigurableEnvironment environment = getEnvironment();
|
||||
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
|
||||
setActiveProfiles(environment, config.getActiveProfiles());
|
||||
}
|
||||
@ -148,6 +148,15 @@ public class SpringBootContextLoader extends AbstractContextLoader {
|
||||
return new SpringApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a new {@link ConfigurableEnvironment} instance. You can override this method
|
||||
* to return something other than {@link StandardEnvironment} if necessary.
|
||||
* @return a {@link ConfigurableEnvironment} instance
|
||||
*/
|
||||
protected ConfigurableEnvironment getEnvironment() {
|
||||
return new StandardEnvironment();
|
||||
}
|
||||
|
||||
private void setActiveProfiles(ConfigurableEnvironment environment,
|
||||
String[] profiles) {
|
||||
TestPropertyValues
|
||||
|
Loading…
Reference in New Issue
Block a user