public class ConfigFileEnvironmentPostProcessor extends Object implements EnvironmentPostProcessor, ApplicationListener<ApplicationPreparedEvent>, 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 |
static String |
CONFIG_LOCATION_PROPERTY |
static String |
CONFIG_NAME_PROPERTY |
static int |
DEFAULT_ORDER |
static String |
INCLUDE_PROFILES_PROPERTY |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
ConfigFileEnvironmentPostProcessor() |
Modifier and Type | Method and Description |
---|---|
protected void |
addPostProcessors(ConfigurableApplicationContext context)
Add appropriate post-processors to post-configure the property-sources.
|
protected void |
addPropertySources(ConfigurableEnvironment environment,
ResourceLoader resourceLoader)
Add config file property sources to the specified environment.
|
protected void |
bindToSpringApplication(ConfigurableEnvironment environment,
SpringApplication application)
Bind the environment to the
SpringApplication . |
int |
getOrder() |
void |
onApplicationEvent(ApplicationPreparedEvent event) |
void |
postProcessEnvironment(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.
|
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 void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application)
EnvironmentPostProcessor
environment
postProcessEnvironment
in interface EnvironmentPostProcessor
environment
- the environment to post-processapplication
- the application to which the environment belongspublic void onApplicationEvent(ApplicationPreparedEvent event)
onApplicationEvent
in interface ApplicationListener<ApplicationPreparedEvent>
protected void addPropertySources(ConfigurableEnvironment environment, ResourceLoader resourceLoader)
environment
- the environment to add source toresourceLoader
- the resource loaderaddPostProcessors(ConfigurableApplicationContext)
protected void bindToSpringApplication(ConfigurableEnvironment environment, SpringApplication application)
SpringApplication
.environment
- the environment to bindapplication
- the application to bind toprotected void addPostProcessors(ConfigurableApplicationContext context)
context
- the context to configurepublic void setOrder(int order)
public 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 © 2015 Pivotal Software, Inc.. All rights reserved.