Apollo + Springboot 整合(多环境版)

(1)Apollo 配置中心创建项目。

(2)将对应环境的相关配置全部添加到配置中心,然后发布。

(3)pom.xml 中加入依赖

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

(4)启动类上添加 @EnableApolloConfig 注解

@SpringBootApplication
@EnableApolloConfig
public class PrpApplication {

    public static void main(String[] args) {
        SpringApplication.run(PrpApplication.class, args);
    }

}

(5)修改原 dev 配置文件如下

app:
  id: xxx #你创建项目AppId

apollo:
  meta: http://xxx.com/config/ #你的apollo配置中心地址(安装的时候有)
  #cluster: myCluster  #集群,没有可不写
  #cacheDir: /opt/apolloDir  #缓存文件
  bootstrap:
    enable: true
    namespaces: application

env: DEV #对应apollo配置中心环境

配置完成后,即可启动项目,获取线上配置。

猜你喜欢

转载自blog.csdn.net/sunnyzyq/article/details/119823598