springboot整合apollo

0. linux中搭建apollo:

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

1.maven依赖

  
        
            com.ctrip.framework.apollo
            apollo-client
            1.4.0
        

 

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

springboot整合apollo_第1张图片

 

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

地址为:configservice服务地址

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

 

 

6.测试

  服务端发布一个配置

springboot整合apollo_第2张图片

 

springboot中通过@Value来获取

  @Value("${test:test}")
    private String  test;

 

你可能感兴趣的:(微服务)