类 ConfigFileApplicationListener
- java.lang.Object
- org.springframework.boot.context.config.ConfigFileApplicationListener
- 所有已实现的接口:
EventListener
,EnvironmentPostProcessor
,org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
,org.springframework.context.event.SmartApplicationListener
,org.springframework.core.Ordered
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:- classpath:
- file:./
- classpath:config/
- file:./config/:
Alternative search locations and names can be specified using
setSearchLocations(String)
andsetSearchNames(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.
字段概要
字段 修饰符和类型 字段 说明 static String
ACTIVE_PROFILES_PROPERTY
The "active profiles" property name.static String
CONFIG_ADDITIONAL_LOCATION_PROPERTY
The "config additional location" property name.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.
构造器概要
构造器 构造器 说明 ConfigFileApplicationListener()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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.int
getOrder()
void
onApplicationEvent(org.springframework.context.ApplicationEvent event)
void
postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, SpringApplication application)
Post-process the givenenvironment
.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)
字段详细资料
ACTIVE_PROFILES_PROPERTY
public static final String ACTIVE_PROFILES_PROPERTY
The "active profiles" property name.- 另请参阅:
- 常量字段值
INCLUDE_PROFILES_PROPERTY
public static final String INCLUDE_PROFILES_PROPERTY
The "includes profiles" property name.- 另请参阅:
- 常量字段值
CONFIG_NAME_PROPERTY
public static final String CONFIG_NAME_PROPERTY
The "config name" property name.- 另请参阅:
- 常量字段值
CONFIG_LOCATION_PROPERTY
public static final String CONFIG_LOCATION_PROPERTY
The "config location" property name.- 另请参阅:
- 常量字段值
CONFIG_ADDITIONAL_LOCATION_PROPERTY
public static final String CONFIG_ADDITIONAL_LOCATION_PROPERTY
The "config additional location" property name.- 另请参阅:
- 常量字段值
DEFAULT_ORDER
public static final int DEFAULT_ORDER
The default order for the processor.- 另请参阅:
- 常量字段值
构造器详细资料
ConfigFileApplicationListener
public ConfigFileApplicationListener()
方法详细资料
supportsEventType
public boolean supportsEventType(Class<? extends org.springframework.context.ApplicationEvent> eventType)
- 指定者:
supportsEventType
在接口中org.springframework.context.event.SmartApplicationListener
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
- 指定者:
onApplicationEvent
在接口中org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
postProcessEnvironment
public void postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, SpringApplication application)
从接口复制的说明:EnvironmentPostProcessor
Post-process the givenenvironment
.- 指定者:
postProcessEnvironment
在接口中EnvironmentPostProcessor
- 参数:
environment
- the environment to post-processapplication
- the application to which the environment belongs
addPropertySources
protected void addPropertySources(org.springframework.core.env.ConfigurableEnvironment environment, org.springframework.core.io.ResourceLoader resourceLoader)
Add config file property sources to the specified environment.- 参数:
environment
- the environment to add source toresourceLoader
- the resource loader- 另请参阅:
addPostProcessors(ConfigurableApplicationContext)
addPostProcessors
protected void addPostProcessors(org.springframework.context.ConfigurableApplicationContext context)
Add appropriate post-processors to post-configure the property-sources.- 参数:
context
- the context to configure
setOrder
public void setOrder(int order)
getOrder
public int getOrder()
- 指定者:
getOrder
在接口中org.springframework.core.Ordered
- 指定者:
getOrder
在接口中org.springframework.context.event.SmartApplicationListener
setSearchLocations
public void setSearchLocations(String locations)
Set the search locations that will be considered as a comma-separated list. Each search location should be a directory path (ending in "/") and it will be prefixed by the file names constructed fromsearch 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 locations
setSearchNames
public void setSearchNames(String names)
Sets the names of the files that should be loaded (excluding file extension) as a comma-separated list.- 参数:
names
- the names to load