Class BootstrapConfigFileApplicationListener
java.lang.Object
org.springframework.cloud.bootstrap.BootstrapConfigFileApplicationListener
- All Implemented Interfaces:
EventListener, org.springframework.boot.EnvironmentPostProcessor, org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>, org.springframework.context.event.SmartApplicationListener, org.springframework.core.Ordered
public class BootstrapConfigFileApplicationListener
extends Object
implements org.springframework.boot.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:
- file:./config/
- file:./config/*/
- file:./
- classpath:config/
- classpath:
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.
- Since:
- 1.0.0
ConfigDataEnvironmentPostProcessor - Author:
- Dave Syer, Phillip Webb, Stephane Nicoll, Andy Wilkinson, EddĂș MelĂ©ndez, Madhura Bhave, Scott Frederick, Olga Maciaszek-Sharma
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe "active profiles" property name.static final StringThe "config additional location" property name.static final StringThe "config location" property name.static final StringThe "config name" property name.static final intThe default order for the processor.static final StringThe "includes profiles" property name.Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddPostProcessors(org.springframework.context.ConfigurableApplicationContext context) Add appropriate post-processors to post-configure the property-sources.protected voidaddPropertySources(org.springframework.core.env.ConfigurableEnvironment environment, @Nullable org.springframework.core.io.ResourceLoader resourceLoader) Add config file property sources to the specified environment.intgetOrder()voidonApplicationEvent(org.springframework.context.ApplicationEvent event) voidpostProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, org.springframework.boot.SpringApplication application) voidsetOrder(int order) voidsetSearchLocations(String locations) Set the search locations that will be considered as a comma-separated list.voidsetSearchNames(String names) Sets the names of the files that should be loaded (excluding file extension) as a comma-separated list.booleansupportsEventType(Class<? extends org.springframework.context.ApplicationEvent> eventType) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.context.event.SmartApplicationListener
getListenerId, supportsSourceType
-
Field Details
-
ACTIVE_PROFILES_PROPERTY
-
INCLUDE_PROFILES_PROPERTY
The "includes profiles" property name.- See Also:
-
CONFIG_NAME_PROPERTY
-
CONFIG_LOCATION_PROPERTY
-
CONFIG_ADDITIONAL_LOCATION_PROPERTY
The "config additional location" property name.- See Also:
-
DEFAULT_ORDER
public static final int DEFAULT_ORDERThe default order for the processor.
-
-
Constructor Details
-
BootstrapConfigFileApplicationListener
public BootstrapConfigFileApplicationListener()
-
-
Method Details
-
supportsEventType
public boolean supportsEventType(Class<? extends org.springframework.context.ApplicationEvent> eventType) - Specified by:
supportsEventTypein interfaceorg.springframework.context.event.SmartApplicationListener
-
onApplicationEvent
public void onApplicationEvent(org.springframework.context.ApplicationEvent event) - Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
-
postProcessEnvironment
public void postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, org.springframework.boot.SpringApplication application) - Specified by:
postProcessEnvironmentin interfaceorg.springframework.boot.EnvironmentPostProcessor
-
addPropertySources
protected void addPropertySources(org.springframework.core.env.ConfigurableEnvironment environment, @Nullable org.springframework.core.io.ResourceLoader resourceLoader) Add config file property sources to the specified environment.- Parameters:
environment- the environment to add source toresourceLoader- the resource loader- See Also:
-
addPostProcessors
protected void addPostProcessors(org.springframework.context.ConfigurableApplicationContext context) Add appropriate post-processors to post-configure the property-sources.- Parameters:
context- the context to configure
-
setOrder
public void setOrder(int order) -
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered- Specified by:
getOrderin interfaceorg.springframework.context.event.SmartApplicationListener
-
setSearchLocations
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 namesand 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).- Parameters:
locations- the search locations
-
setSearchNames
Sets the names of the files that should be loaded (excluding file extension) as a comma-separated list.- Parameters:
names- the names to load
-