springboot整合apollo

0. linux中搭建apollo:

       https://blog.csdn.net/qq_34707456/article/details/103702828

1.maven依赖

  <!--apollo客户端依赖     -->
        <dependency>
            <groupId>com.ctrip.framework.apollo</groupId>
            <artifactId>apollo-client</artifactId>
            <version>1.4.0</version>
        </dependency>

2.application.yml配置

#apollo相关配置
app:
  #项目的app-id
  id: 19970322
apollo:
  #configservice服务地址
  meta: http://39.108.107.163:8002
  bootstrap:
    enabled: true
    eagerLoad:
      enabled: true

3.通过配置文件来指定env=YOUR-ENVIRONMENT

对于Mac/Linux,文件位置为 /opt/settings/server.properties
对于Windows,文件位置为 C:\opt\settings\server.properties
目前,env支持以下几个值(大小写不敏感):
DEV, FAT, UAT, PRO
 

4.启动类上加@EnableApolloConfig

5.如果apollo服务端再linux上部署,本地为windows连接则需要配置jvm启动参数

地址为:configservice服务地址

-Dapollo.configService=http://39.108.107.163:8002

6.测试

  服务端发布一个配置

springboot中通过@Value来获取

  @Value("${test:test}")
    private String  test;
发布了68 篇原创文章 · 获赞 93 · 访问量 8493

猜你喜欢

转载自blog.csdn.net/qq_34707456/article/details/103745839