Apollo搭建踩過的那些坑

環境:

阿里雲 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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章