Apollo配置中心的基本使用

1、首先创建SpringBoot项目,保证可以正常启动访问

2、加入依赖包

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

3、引入注解@EnableApolloConfig

@RequestMapping("/apollo")
@RestController
public class ApolloController {
    @Value("${sms_time:1}")
    private Integer smsTime;

    @GetMapping("/smsTime")
    public Object smsTime() {
        return smsTime;
    }

}

4、配置key

5、配置连接参数

app.id=qq
apollo.bootstrap.enabled = true
#eureka注册中心地址
apollo.meta=http://gaojs.eureka.frpvip.wlphp.com:88/
apollo.bootstrap.eagerLoad.enabled=false
apollo.bootstrap.namespaces=application
env=dev

6、测试 ,启动jar

验证

 采坑总结:

一)应用id设置

app.id is not available from System Property and /META-INF/app.properties. It is set to null

配置文件,需要加入appid配置

二)环境变量

Environment is set to null. Because it is not available in either (1) JVM system property 'env', (2) OS env variable 'ENV' nor (3) property 'env' from the properties InputStream.

环境变量需要指定

三)元数据地址指定

2022-05-06 14:54:34.246  WARN 4364 --- [           main] c.c.f.a.i.DefaultMetaServerProvider      : Could not find meta server address, because it is not available in neither (1) JVM system property 'apollo.meta',

(2) OS env variable 'APOLLO_META' (3) property 'apollo.meta' from server.properties nor (4) property 'apollo.meta' from app.properties

配置文件地址需要指定

四)网络问题

网络问题,导致超时,上传到apollo同一个网段,问题解决

2022-05-06 17:07:45.444  WARN 5700 --- [           main] c.c.f.a.i.RemoteConfigRepository         : Load config failed, will retry in 1 SECONDS. appId: qq, cluster: default, namespaces: application
2022-05-06 17:07:46.439  WARN 5700 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService    : Long polling failed, will retry in 2 seconds. appId: qq, cluster: default, namespaces: application, long polling url: http://192.168.0.12:8080/notifications/v2?cluster=default&appId=qq&ip=172.16.224.134&notifications=%5B%7B%22namespaceName%22%3A%22application%22%2C%22notificationId%22%3A-1%7D%5D, reason: Could not complete get operation [Cause: connect timed out]

访问地址公开:

http://gaojs.apollo.frpvip.wlphp.com:88/

用户名密码:apollo/admin ,如果服务不可用请邮件告知904456849@qq.com

系统说明本系统属于原创系统 ,主要用来做考试练习使用
个人说明原创不易,欢迎打赏
支付宝赞助
微信赞助

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gaojingsong

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值