org.springframework.boot.context.initializer
Class ConfigFileApplicationContextInitializer

java.lang.Object
  extended by org.springframework.boot.context.initializer.ConfigFileApplicationContextInitializer
All Implemented Interfaces:
org.springframework.beans.factory.Aware, SpringApplicationInitializer, org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>, org.springframework.context.EnvironmentAware, org.springframework.core.Ordered

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.

Author:
Dave Syer, Phillip Webb

Field Summary
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
ConfigFileApplicationContextInitializer()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigFileApplicationContextInitializer

public ConfigFileApplicationContextInitializer()
Method Detail

initialize

public void initialize(SpringApplication springApplication,
                       String[] args)
Binds the early 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").

Specified by:
initialize in interface SpringApplicationInitializer
Parameters:
springApplication - the spring application.
args - the run arguments

initialize

public void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext)
Specified by:
initialize in interface org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>

setEnvironment

public void setEnvironment(org.springframework.core.env.Environment environment)
Specified by:
setEnvironment in interface org.springframework.context.EnvironmentAware

setOrder

public void setOrder(int order)

getOrder

public int getOrder()
Specified by:
getOrder in interface org.springframework.core.Ordered

setNames

public void setNames(String names)
Sets the names of the files that should be loaded (excluding file extension) as a comma separated list. Defaults to "application".


setSearchLocations

public void setSearchLocations(String[] searchLocations)
Set the search locations that will be considered.



Copyright © 2013. All Rights Reserved.