类 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) 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.

    • 方法详细资料

      • 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>
      • 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 to
        resourceLoader - 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 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).
        参数:
        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