public class ConfigFileApplicationContextInitializer extends Object implements org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>, SpringApplicationInitializer, org.springframework.core.Ordered, org.springframework.context.EnvironmentAware
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.
Constructor and Description |
---|
ConfigFileApplicationContextInitializer() |
Modifier and Type | Method and Description |
---|---|
int |
getOrder() |
void |
initialize(org.springframework.context.ConfigurableApplicationContext applicationContext) |
void |
initialize(SpringApplication springApplication,
String[] args)
Binds the early
Environment to the SpringApplication . |
void |
setEnvironment(org.springframework.core.env.Environment environment) |
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 |
setSearchLocations(String[] searchLocations)
Set the search locations that will be considered.
|
public ConfigFileApplicationContextInitializer()
public void initialize(SpringApplication springApplication, String[] args)
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").initialize
in interface SpringApplicationInitializer
springApplication
- the spring application.args
- the run argumentspublic void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext)
initialize
in interface org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
public void setEnvironment(org.springframework.core.env.Environment environment)
setEnvironment
in interface org.springframework.context.EnvironmentAware
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)
Copyright © 2013. All rights reserved.