问题一:
没有给springboot项目指定环境
2022-08-14 13:24:34.973 INFO 13748 --- [ main] c.c.f.f.i.p.DefaultApplicationProvider : App ID is set to test by app.id property from System Property
2022-08-14 13:24:34.975 INFO 13748 --- [ main] c.c.f.f.i.p.DefaultServerProvider : 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.
问题解决:
给项目指定环境即可:
问题二:
springBoot项目拉取不到Apollo的配置文件
2022-08-14 13:35:46.908 INFO 8236 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CESHI/localhost:ceshi:1234 - registration status: 204
2022-08-14 13:35:47.813 WARN 8236 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 8 seconds. appId: test, cluster: default, namespaces: application, long polling url: http://127.0.0.1:8001/notifications/v2?cluster=default&appId=test&ip=192.168.32.1¬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]
分析原因:发现轮训的地址访问不到
将地址127.0.0.1换成meteServer地址后可以访问成功:
官方说明:我们需要跳过metaServer发现
问题解决:
我采用的是将 在启动脚本中指定apollo.configService 地址:
-Dapollo.configService=http://192.168.1.12:8001
附带apollo需要的配置文件以及pom文件:
#apollo需要导入的pom文件
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.9.1</version>
</dependency>
@apollo 相关的配置文件
app:
id: test apollo的应用ID
apollo:
meta: http://192.168.1.12:8001 metaServer地址 安装好后可以在apollo页面 管理员工具->系统信息中查看到
bootstrap:
enabled: true
eagerLoad:
enabled: true
namespaces: application
cache-dir: E:\workspace\demo\.mvn 配置文件的缓存地址