Search in sources :

Example 1 with ConfigFileApplicationListener

use of org.springframework.boot.context.config.ConfigFileApplicationListener in project spring-cloud-config by spring-cloud.

the class NativeEnvironmentRepository method findOne.

@Override
public Environment findOne(String config, String profile, String label) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(PropertyPlaceholderAutoConfiguration.class);
    ConfigurableEnvironment environment = getEnvironment(profile);
    builder.environment(environment);
    builder.web(WebApplicationType.NONE).bannerMode(Mode.OFF);
    if (!logger.isDebugEnabled()) {
        // Make the mini-application startup less verbose
        builder.logStartupInfo(false);
    }
    String[] args = getArgs(config, profile, label);
    // Explicitly set the listeners (to exclude logging listener which would change
    // log levels in the caller)
    builder.application().setListeners(Arrays.asList(new ConfigFileApplicationListener()));
    ConfigurableApplicationContext context = builder.run(args);
    environment.getPropertySources().remove("profiles");
    try {
        return clean(new PassthruEnvironmentRepository(environment).findOne(config, profile, label));
    } finally {
        context.close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ConfigFileApplicationListener(org.springframework.boot.context.config.ConfigFileApplicationListener)

Aggregations

SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)1 ConfigFileApplicationListener (org.springframework.boot.context.config.ConfigFileApplicationListener)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1