`
234390216
  • 浏览: 10187807 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
博客专栏
A5ee55b9-a463-3d09-9c78-0c0cf33198cd
Oracle基础
浏览量:460516
Ad26f909-6440-35a9-b4e9-9aea825bd38e
springMVC介绍
浏览量:1771200
Ce363057-ae4d-3ee1-bb46-e7b51a722a4b
Mybatis简介
浏览量:1395015
Bdeb91ad-cf8a-3fe9-942a-3710073b4000
Spring整合JMS
浏览量:393708
5cbbde67-7cd5-313c-95c2-4185389601e7
Ehcache简介
浏览量:678018
Cc1c0708-ccc2-3d20-ba47-d40e04440682
Cas简介
浏览量:529030
51592fc3-854c-34f4-9eff-cb82d993ab3a
Spring Securi...
浏览量:1178306
23e1c30e-ef8c-3702-aa3c-e83277ffca91
Spring基础知识
浏览量:460976
4af1c81c-eb9d-365f-b759-07685a32156e
Spring Aop介绍
浏览量:149927
2f926891-9e7a-3ce2-a074-3acb2aaf2584
JAXB简介
浏览量:66670
社区版块
存档分类
最新评论

Spring Cloud(02)——bootstrap文件介绍

阅读更多

bootstrap文件介绍

bootstrap的中文翻译是“引导程序”的意思。Spring中的ApplicationContext是会有父子关系的。Spring Cloud初始化的ApplicationContext叫bootstrap ApplicationContext,之后会创建一些子的ApplicationContext。这个bootstrap ApplicationContext如果在初始化的过程中是可以接收一些外部属性控制的,那么对应的属性需要配置在bootstrap.yml或bootstrap.properties文件中。默认会在Classpath的根路径或config路径下寻找它们。ApplicationContext是有父子关系的,那依托于ApplicationContext的Environment也相当于间接的有了父子关系,所以定义在bootstrap.yml文件中的属性值也可以被我们自己定义的bean使用。只是它里面的值会被我们定义在application.yml中的相同属性的值覆盖掉。bootstrap ApplicationContext寻找的外部属性文件的名字不一定是bootstrap,它可以通过系统属性spring.cloud.bootstrap.name进行指定,比如通过系统属性spring.cloud.bootstrap.name指定bootstrap属性文件的名称是application,即会在Classpath根目录或config目录下寻找application.yml或application.properties文件。也可以通过系统属性spring.cloud.bootstrap.location指定bootstrap文件的位置,它们的用法就类似于Spring Boot中指定配置文件的spring.config.name和spring.config.location`。

如果在bootstrap.yml中指定了spring.profiles.active=dev,则bootstrap ApplicationContext寻找配置文件时还会寻找bootstrap-dev.yml文件。

如果有需要我们也需要在bootstrap ApplicationContext中做一些事情,比如定义一些bean等,则我们也可以定义一个使用@Configuration标注的Class,然后在Classpath下的META-INF/spring.factories文件中通过org.springframework.cloud.bootstrap.BootstrapConfiguration属性指定@Configuration类的名称。比如下面这样一个@Configuration类。

@Configuration
public class BootstrapConfiguration {

  @Bean
  public TestService testService() {
    return new TestService();
  }

}

那么在spring.factories文件中需要这样定义。

org.springframework.cloud.bootstrap.BootstrapConfiguration=com.elim.learn.spring.cloud.config.client.BootstrapConfiguration

(注:本文是基于Spring Cloud Finchley.SR1所写)

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics