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:
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower 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.

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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The "active profiles" property name.
    static final String
    The "config additional location" property name.
    static final String
    The "config location" property name.
    static final String
    The "config name" property name.
    static final int
    The default order for the processor.
    static final String
    The "includes profiles" property name.

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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, @Nullable org.springframework.core.io.ResourceLoader resourceLoader)
    Add config file property sources to the specified environment.
    int
     
    void
    onApplicationEvent(org.springframework.context.ApplicationEvent event)
     
    void
    postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, org.springframework.boot.SpringApplication application)
     
    void
    setOrder(int order)
     
    void
    Set the search locations that will be considered as a comma-separated list.
    void
    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)
     

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.context.ApplicationListener

    supportsAsyncExecution

    Methods inherited from interface org.springframework.context.event.SmartApplicationListener

    getListenerId, supportsSourceType
  • Field Details

    • ACTIVE_PROFILES_PROPERTY

      public static final String ACTIVE_PROFILES_PROPERTY
      The "active profiles" property name.
      See Also:
    • INCLUDE_PROFILES_PROPERTY

      public static final String INCLUDE_PROFILES_PROPERTY
      The "includes profiles" property name.
      See Also:
    • CONFIG_NAME_PROPERTY

      public static final String CONFIG_NAME_PROPERTY
      The "config name" property name.
      See Also:
    • CONFIG_LOCATION_PROPERTY

      public static final String CONFIG_LOCATION_PROPERTY
      The "config location" property name.
      See Also:
    • CONFIG_ADDITIONAL_LOCATION_PROPERTY

      public static final String CONFIG_ADDITIONAL_LOCATION_PROPERTY
      The "config additional location" property name.
      See Also:
    • DEFAULT_ORDER

      public static final int DEFAULT_ORDER
      The 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:
      supportsEventType in interface org.springframework.context.event.SmartApplicationListener
    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.ApplicationEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.ApplicationEvent>
    • postProcessEnvironment

      public void postProcessEnvironment(org.springframework.core.env.ConfigurableEnvironment environment, org.springframework.boot.SpringApplication application)
      Specified by:
      postProcessEnvironment in interface org.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 to
      resourceLoader - 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:
      getOrder in interface org.springframework.core.Ordered
      Specified by:
      getOrder in interface 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 from 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).
      Parameters:
      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.
      Parameters:
      names - the names to load