public class ConfigFileApplicationListener extends Object implements org.springframework.context.ApplicationListener<SpringApplicationEnvironmentAvailableEvent>, org.springframework.core.Ordered
ApplicationContextInitializer
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 locations and names can be specified using
setSearchLocations(String[])
and setNames(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 or alternatively the 'spring.config.location' property can be used to specify an exact resource location.
Modifier and Type | Class and Description |
---|---|
static interface |
ConfigFileApplicationListener.PropertySourceLoaderFactory |
Constructor and Description |
---|
ConfigFileApplicationListener() |
Modifier and Type | Method and Description |
---|---|
int |
getOrder() |
void |
onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event)
Binds the early
Environment to the SpringApplication . |
void |
setNames(String names)
Sets the names of the files that should be loaded (excluding file extension) as a
comma separated list.
|
void |
setOrder(int order) |
void |
setPropertySourceLoaderFactory(ConfigFileApplicationListener.PropertySourceLoaderFactory propertySourceLoaderFactory) |
void |
setSearchLocations(String[] searchLocations)
Set the search locations that will be considered.
|
public void onApplicationEvent(SpringApplicationEnvironmentAvailableEvent event)
Environment
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").onApplicationEvent
in interface org.springframework.context.ApplicationListener<SpringApplicationEnvironmentAvailableEvent>
public void setOrder(int order)
public int getOrder()
getOrder
in interface org.springframework.core.Ordered
public void setNames(String names)
public void setSearchLocations(String[] searchLocations)
public void setPropertySourceLoaderFactory(ConfigFileApplicationListener.PropertySourceLoaderFactory propertySourceLoaderFactory)
propertySourceLoaderFactory
- the factory to setCopyright © 2014. All rights reserved.