mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge pull request #10740 from green-leaves/spring-boot-context-loader-flexible-environment
* pr/10740: Support custom SpringBootContextLoader environment
This commit is contained in:
commit
243fa9cf8d
@ -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