public class ConfigFileApplicationListener extends Object implements EnvironmentPostProcessor, org.springframework.context.event.SmartApplicationListener, org.springframework.core.Ordered
EnvironmentPostProcessor that configures the context environment by loading
properties from well known file locations. By default properties will be loaded from
'application.properties' and/or 'application.yml' files in the following locations:
Alternative search locations and names can be specified using
setSearchLocations(String) and setSearchNames(String).
Additional files will also be loaded based on active profiles. For example if a 'web' profile is active 'application-web.properties' and 'application-web.yml' will be considered.
The 'spring.config.name' property can be used to specify an alternative name to load and the 'spring.config.location' property can be used to specify alternative search locations or specific files.
Configuration properties are also bound to the SpringApplication. This makes it
possible to set SpringApplication properties dynamically, like the sources
("spring.main.sources" - a CSV list) the flag to indicate a web environment
("spring.main.web_environment=true") or the flag to switch off the banner
("spring.main.show_banner=false").
| Modifier and Type | Field and Description |
|---|---|
static String |
ACTIVE_PROFILES_PROPERTY
The "active profiles" property name.
|
static String |
APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME
Name of the application configuration
PropertySource. |
static String |
CONFIG_LOCATION_PROPERTY
The "config location" property name.
|
static String |
CONFIG_NAME_PROPERTY
The "config name" property name.
|
static int |
DEFAULT_ORDER
The default order for the processor.
|
static String |
INCLUDE_PROFILES_PROPERTY
The "includes profiles" property name.
|
| Constructor and Description |
|---|
ConfigFileApplicationListener() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPostProcessors(org.springframework.context.ConfigurableApplicationContext context)
Add appropriate post-processors to post-configure the property-sources.
|
protected void |
addPropertySources(org.springframework.core.env.ConfigurableEnvironment environment,
org.springframework.core.io.ResourceLoader resourceLoader)
Add config file property sources to the specified environment.
|
protected void |
bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment,
SpringApplication application)
Bind the environment to the
SpringApplication. |
int |
getOrder() |
void |
onApplicationEvent(org.springframework.context.ApplicationEvent event) |
void |
postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment,
SpringApplication application)
Post-process the given
environment. |
void |
setOrder(int order) |
void |
setSearchLocations(String locations)
Set the search locations that will be considered as a comma-separated list.
|
void |
setSearchNames(String names)
Sets the names of the files that should be loaded (excluding file extension) as a
comma-separated list.
|
boolean |
supportsEventType(Class<? extends org.springframework.context.ApplicationEvent> eventType) |
boolean |
supportsSourceType(Class<?> aClass) |
public static final String ACTIVE_PROFILES_PROPERTY
public static final String INCLUDE_PROFILES_PROPERTY
public static final String CONFIG_NAME_PROPERTY
public static final String CONFIG_LOCATION_PROPERTY
public static final int DEFAULT_ORDER
public static final String APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME
PropertySource.public boolean supportsEventType(Class<? extends org.springframework.context.ApplicationEvent> eventType)
supportsEventType in interface org.springframework.context.event.SmartApplicationListenerpublic boolean supportsSourceType(Class<?> aClass)
supportsSourceType in interface org.springframework.context.event.SmartApplicationListenerpublic void onApplicationEvent(org.springframework.context.ApplicationEvent event)
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>public void postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment,
SpringApplication application)
EnvironmentPostProcessorenvironment.postProcessEnvironment in interface EnvironmentPostProcessorenvironment - the environment to post-processapplication - the application to which the environment belongsprotected void addPropertySources(org.springframework.core.env.ConfigurableEnvironment environment,
org.springframework.core.io.ResourceLoader resourceLoader)
environment - the environment to add source toresourceLoader - the resource loaderaddPostProcessors(ConfigurableApplicationContext)protected void bindToSpringApplication(org.springframework.core.env.ConfigurableEnvironment environment,
SpringApplication application)
SpringApplication.environment - the environment to bindapplication - the application to bind toprotected void addPostProcessors(org.springframework.context.ConfigurableApplicationContext context)
context - the context to configurepublic void setOrder(int order)
public int getOrder()
getOrder in interface org.springframework.core.Orderedpublic void setSearchLocations(String locations)
search names and
profiles (if any) plus file extensions supported by the properties loaders.
Locations are considered in the order specified, with later items taking precedence
(like a map merge).locations - the search locationspublic void setSearchNames(String names)
names - the names to loadCopyright © 2018 Pivotal Software, Inc.. All rights reserved.