zoukankan      html  css  js  c++  java
  • java练习生

    一、添加依赖

    <dependency>
        <groupId>com.ctrip.framework.apollo</groupId>
        <artifactId>apollo-client</artifactId>
        <version>1.4.0</version>
    </dependency>

    二、添加配置(bootstrap.yml)

     bootstrap.yml 先于 application.yml 加载

    bootstrap.yml(bootstrap.properties)用来在程序引导时执行,应用于更加早期配置信息读取,可以使用来配置application.yml中使用到参数等
    application.yml(application.properties) 应用程序特有配置信息,可以用来配置后续各个模块中需使用的公共参数等。

    app:
      id: ttt # apollo配置的appid
     
    apollo:
      meta: http://dev.config.apollo.xxx.com.local
      bootstrap:
        enabled: true
        namespaces: application,test
        eagerLoad:
          enabled: true
     
    ---
    spring:
      profiles: sit
     
    apollo:
      meta: http://sit.config.apollo.xxx.com.local
      bootstrap:
        enabled: true
        namespaces: application,test
        eagerLoad:
          enabled: true
    ---
    spring:
      profiles: uat
     
    apollo:
      meta: http://uat.config.apollo.xxx.com.local
      bootstrap:
        enabled: true
        namespaces: application,test
        eagerLoad:
          enabled: true
    ---
    spring:
      profiles: prod
     
    apollo:
      meta: http://pro.config.apollo.xxx.com.local
      bootstrap:
        enabled: true
        namespaces: application,test
        eagerLoad:
          enabled: true

    文件中加---分隔符,相当于后面的内容独立出一个配置文件,用于区分运行环境。

    DEV环境:DEV顾名思义就是develop,即代码开发的环境。

    SIT环境:System Integration Test系统集成测试,开发人员自己测试流程是否走通。

    UAT环境:User Acceptance Test用户验收测试,由专门的测试人员验证,验收完成才能上生产环境。

    PRO环境:production 生产环境。

    三、使用

    3.1 在其他配置文件中读取apollo配置

    cur-application-port: ${server.port}

    3.2 在代码中读取apollo配置

    @Value("${server.port:8888}")
    public String curAppPort;

    可以通过冒号给配置添加默认值,这样当配置不存在时会直接使用默认值,而避免抛异常。

  • 相关阅读:
    phalcon之视图缓存
    Java NIO框架Netty教程(一) – Hello Netty
    setsockopt的作用
    支持向量机通俗导论(理解SVM的三层境地)
    quartz中的corn表达式(转)
    Applet 数字签名技术全然攻略
    SJTU 3001. 二哥的幸运
    OGRE之跳出漫长的编译等待
    VB.NET 数组的定义 动态使用 多维数组
    【Python】用Python的“结巴”模块进行分词
  • 原文地址:https://www.cnblogs.com/ariter/p/14216105.html
Copyright © 2011-2022 走看看