bootstrap file description
bootstrap the Chinese translation is "bootstrap" means. In Spring ApplicationContext there will be parent-child relationship. Spring Cloud initialization ApplicationContext called bootstrap ApplicationContext, after a number of sub ApplicationContext created. If the bootstrap ApplicationContext properties may receive some external control of the initialization process, then the corresponding property on or disposed bootstrap.yml bootstrap.properties file. The default will look for them in the root path of Classpath or config path. ApplicationContext is parent-child relationship, and that relying on the ApplicationContext of Environment is also equivalent to an indirect relationship with the father and son, so the definition in bootstrap.yml file property values can also be used by our own definition of bean. But the value inside it will be overwritten values for the same property we define in application.yml in. bootstrap ApplicationContext to find the name of an external properties file is not necessarily bootstrap, it can through the system attribute spring.cloud.bootstrap.name
is specified, such as through the system attribute spring.cloud.bootstrap.name
specifies the name of bootstrap properties file that application, namely in the Classpath will look application.yml root directory or a directory or config application.properties file. System property can also spring.cloud.bootstrap.location
specify the location of the bootstrap file, their usage is similar Spring Boot specified in the configuration file spring.config.name
and spring.config.location`.
If you specify in bootstrap.yml in
spring.profiles.active=dev
, you will find the bootstrap ApplicationContext bootstrap-dev.yml file to find the configuration file.
If necessary we also need to do some things in bootstrap ApplicationContext, such as the definition of some of the bean and so on, then we can define a use @Configuration
marked Class, and then in the Classpath META-INF/spring.factories
by file org.springframework.cloud.bootstrap.BootstrapConfiguration
attribute specifies the @Configuration
name of the class. The following example of such a @Configuration
class.
@Configuration
public class BootstrapConfiguration {
@Bean
public TestService testService() {
return new TestService();
}
}
Then the spring.factories
need for such definition file.
org.springframework.cloud.bootstrap.BootstrapConfiguration=com.elim.learn.spring.cloud.config.client.BootstrapConfiguration
(Note: This article is written based on Spring Cloud Finchley.SR1)