use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class SpringApplication method run.
/**
* Run the Spring application, creating and refreshing a new
* {@link ApplicationContext}.
* @param args the application arguments (usually passed from a Java main method)
* @return a running {@link ApplicationContext}
*/
public ConfigurableApplicationContext run(String... args) {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
ConfigurableApplicationContext context = null;
Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
configureHeadlessProperty();
SpringApplicationRunListeners listeners = getRunListeners(args);
listeners.starting();
try {
ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
configureIgnoreBeanInfo(environment);
bindToSpringApplication(environment);
Banner printedBanner = printBanner(environment);
context = createApplicationContext();
exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class, new Class[] { ConfigurableApplicationContext.class }, context);
prepareContext(context, environment, listeners, applicationArguments, printedBanner);
refreshContext(context);
afterRefresh(context, applicationArguments);
listeners.finished(context, null);
stopWatch.stop();
if (this.logStartupInfo) {
new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
}
return context;
} catch (Throwable ex) {
handleRunFailure(context, listeners, exceptionReporters, ex);
throw new IllegalStateException(ex);
}
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class SpringApplication method prepareEnvironment.
private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments) {
// Create and configure the environment
ConfigurableEnvironment environment = getOrCreateEnvironment();
configureEnvironment(environment, applicationArguments.getSourceArgs());
listeners.environmentPrepared(environment);
if (isWebEnvironment(environment) && this.webApplicationType == WebApplicationType.NONE) {
environment = convertToStandardEnvironment(environment);
}
return environment;
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class RelaxedPropertyResolver method getSubProperties.
/**
* Return a Map of all values from all underlying properties that start with the
* specified key. NOTE: this method can only be used if the underlying resolver is a
* {@link ConfigurableEnvironment}.
* @param keyPrefix the key prefix used to filter results
* @return a map of all sub properties starting with the specified key prefix.
* @see PropertySourceUtils#getSubProperties
*/
public Map<String, Object> getSubProperties(String keyPrefix) {
Assert.isInstanceOf(ConfigurableEnvironment.class, this.resolver, "SubProperties not available.");
ConfigurableEnvironment env = (ConfigurableEnvironment) this.resolver;
return PropertySourceUtils.getSubProperties(env.getPropertySources(), this.prefix, keyPrefix);
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class RelaxedPropertyResolver method ignoringUnresolvableNestedPlaceholders.
/**
* Return a property resolver for the environment, preferring one that ignores
* unresolvable nested placeholders.
* @param environment the source environment
* @param prefix the prefix
* @return a property resolver for the environment
* @since 1.4.3
*/
public static RelaxedPropertyResolver ignoringUnresolvableNestedPlaceholders(Environment environment, String prefix) {
Assert.notNull(environment, "Environment must not be null");
PropertyResolver resolver = environment;
if (environment instanceof ConfigurableEnvironment) {
resolver = new PropertySourcesPropertyResolver(((ConfigurableEnvironment) environment).getPropertySources());
((PropertySourcesPropertyResolver) resolver).setIgnoreUnresolvableNestedPlaceholders(true);
}
return new RelaxedPropertyResolver(resolver, prefix);
}
use of org.springframework.core.env.ConfigurableEnvironment in project spring-boot by spring-projects.
the class DelegatingApplicationContextInitializer method initialize.
@Override
public void initialize(ConfigurableApplicationContext context) {
ConfigurableEnvironment environment = context.getEnvironment();
List<Class<?>> initializerClasses = getInitializerClasses(environment);
if (!initializerClasses.isEmpty()) {
applyInitializerClasses(context, initializerClasses);
}
}
Aggregations