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

* pr/10740:
  Support custom SpringBootContextLoader environment
This commit is contained in:
Phillip Webb 2017-11-02 21:31:27 -07:00
commit 243fa9cf8d

View File

@ -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