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¬ifications=%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
系统说明 | 本系统属于原创系统 ,主要用来做考试练习使用 |
---|---|
个人说明 | 原创不易,欢迎打赏 |
支付宝赞助 | |
微信赞助 |