Commit 243fa9cf authored by Phillip Webb's avatar Phillip Webb

Merge pull request #10740 from green-leaves/spring-boot-context-loader-flexible-environment

* pr/10740:
  Support custom SpringBootContextLoader environment
parents b58f1f00 fae7a09b
...@@ -105,7 +105,7 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -105,7 +105,7 @@ public class SpringBootContextLoader extends AbstractContextLoader {
application.setMainApplicationClass(config.getTestClass()); application.setMainApplicationClass(config.getTestClass());
application.addPrimarySources(Arrays.asList(configClasses)); application.addPrimarySources(Arrays.asList(configClasses));
application.getSources().addAll(Arrays.asList(configLocations)); application.getSources().addAll(Arrays.asList(configLocations));
ConfigurableEnvironment environment = new StandardEnvironment(); ConfigurableEnvironment environment = getEnvironment();
if (!ObjectUtils.isEmpty(config.getActiveProfiles())) { if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
setActiveProfiles(environment, config.getActiveProfiles()); setActiveProfiles(environment, config.getActiveProfiles());
} }
...@@ -148,6 +148,15 @@ public class SpringBootContextLoader extends AbstractContextLoader { ...@@ -148,6 +148,15 @@ public class SpringBootContextLoader extends AbstractContextLoader {
return new SpringApplication(); 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, private void setActiveProfiles(ConfigurableEnvironment environment,
String[] profiles) { String[] profiles) {
TestPropertyValues 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