Commit fae7a09b authored by Nguyen Duy Tiep's avatar Nguyen Duy Tiep Committed by Phillip Webb

Support custom SpringBootContextLoader environment

Provide a `getEnvironment` method in `SpringBootContextLoader` to allow
specialized `ConfigurableEnvironment` implementations to be used.

Closes gh-10740
parent b58f1f00
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment