环境:
阿里云 CentOS
Java 8
Apollo 1.1
问题一
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.ctrip.framework.apollo.tracer.Tracer
at com.ctrip.framework.apollo.build.ApolloInjector.getInstance(ApolloInjector.java:37)
at com.ctrip.framework.apollo.ConfigService.getManager(ConfigService.java:25)
at com.ctrip.framework.apollo.ConfigService.getConfig(ConfigService.java:61)
问题解析:
只在Maven中导入了client依赖
问题解决:
导入同版本的apollo-core依赖
问题二
Caused by: com.ctrip.framework.apollo.exceptions.ApolloConfigException: Unable to initialize Apollo Spring Injector!
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:24)
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInstance(SpringInjector.java:37)
... 14 more
Caused by: java.lang.NoClassDefFoundError: com/google/inject/Module
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:22)
... 15 more
问题解析:
从报错信息可以看到是缺少部分类,通过查询类名得知这几个依赖
问题解决:
除了core和client,还需要导入guava等多个依赖
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>
问题三
Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository,
reason: Load Apollo Config failed - appId: bitongchong_bos, cluster: default, namespace: application,
url: http://此处是私有ip:8080/configs/bitongchong_bos/default/application?ip=192.168.102.1&messages=%7B%22details%22%3A%7B%22bitongchong_bos%2Bdefault%2Bapplication%22%3A6%7D%7D&releaseKey=20190803112627-2b5dd0e414976d16
[Cause: Could not complete get operation [Cause: connect timed out]]
问题解析:
这个是部署在云服务器上时才会遇到的坑,这个时候eureka实体地址不经过设置,会直接被解析为云服务器内网地址,而非公网地址,因此不能够正常访问,需要仔细查看是否存在这个问题。
问题解决:
手动进行设置eureka 实体地址,以quick-start那个教程的流程为例,需要在demo.sh中的check Java手动指定公网地址
-Deureka.instance.ip-address=公网地址
问题四
2020-03-04 01:34:28.169 WARN 21840 --- [ main] c.c.f.a.i.AbstractConfigRepository : Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Get config services failed from http://xx.xx.xx.xx:8070/services/config?appId=SPOC_Platform&ip=192.168.102.1 [Cause: Could not complete get operation [Cause: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ [Cause: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $]]]
2020-03-04 01:34:30.511 WARN 21840 --- [ main] c.c.f.a.i.LocalFileConfigRepository : Sync config from upstream repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository failed, reason: Get config services failed from http://xx.xx.xx.xx:8070/services/config?appId=SPOC_Platform&ip=192.168.102.1 [Cause: Could not complete get operation [Cause: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $ [Cause: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $]]]
问题解析:
这个是未对apollo.meta 属性进行正确赋值,必须是eureka的地址和端口,就是你输入这个url+端口的时候跳转到的是eureka这个界面,而非apollo管理页面,否则必定报错
问题解决:
如果用的是quick-start这个官方教程的话,将8070修改为8080即可
-Dapollo.meta=http://我的服务器地址:8080 -Denv=dev