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;

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

  • 相关阅读:
    自动交互式脚本--expect
    如何搭建web服务器 使用Nginx搭建反向代理服务器
    linux安装yaf(ubuntu教程)
    如何使用Apache的ab工具进行网站性能测试
    网虚拟主机----云服务器
    handlebars Helper用法
    网络基础知识学习
    使用清华开源镜像安装tensorflow
    安卓开发笔记(二十五):ViewPager的简单介绍和使用
    轻松搞定表白女朋友:Android版APP (零基础也可前往Github免费下载软件)
  • 原文地址:https://www.cnblogs.com/ariter/p/14216105.html
Copyright © 2011-2022 走看看