共計 2421 個字符,預計需要花費 7 分鐘才能閱讀完成。
本文丸趣 TV 小編為大家詳細介紹“如何構建 Ribbon 程序”,內容詳細,步驟清晰,細節處理妥當,希望這篇“如何構建 Ribbon 程序”文章能幫助大家解決疑惑,下面跟著丸趣 TV 小編的思路慢慢深入,一起來學習新知識吧。
之前在 eclipse 中單兒構建第一個 Ribbon 時,只需要加入以下依賴即可:
dependencies
dependency
groupId com.netflix.ribbon /groupId
artifactId ribbon /artifactId
version 2.2.2 /version
/dependency
dependency
groupId com.netflix.ribbon /groupId
artifactId ribbon-httpclient /artifactId
version 2.2.2 /version
/dependency
/dependencies
但是以上的依賴,單獨在命令行中使用 Maven 命令構建,或者在 IDEA 中構建,則會拋出異常,信息如下:
[ERROR] 符號: 變量 ConfigurationManager
[ERROR] 位置: 類 org.crazyit.cloud.TestPingUrlConfig
[ERROR] /D:/s_book/Spring Cloud/codes/04/4.2/first-ribbon-client/src/main/java/org/crazyit/cloud/TestPingUrlConfig.java:[19,17] 找不到符號
[ERROR] 符號: 變量 ConfigurationManager
[ERROR] 位置: 類 org.crazyit.cloud.TestPingUrlConfig
[ERROR] /D:/s_book/Spring Cloud/codes/04/4.2/first-ribbon-client/src/main/java/org/crazyit/cloud/TestPingUrlConfig.java:[23,17] 找不到符號
[ERROR] 符號: 變量 ConfigurationManager
[ERROR] 位置: 類 org.crazyit.cloud.TestPingUrlConfig
[ERROR] /D:/s_book/Spring Cloud/codes/04/4.2/first-ribbon-client/src/main/java/org/crazyit/cloud/TestRestClient.java:[14,17] 找不到符號
[ERROR] 符號: 變量 ConfigurationManager
[ERROR] 位置: 類 org.crazyit.cloud.TestRestClient
[ERROR] /D:/s_book/Spring Cloud/codes/04/4.2/first-ribbon-client/src/main/java/org/crazyit/cloud/TestRestClient.java:[25,49] 無法訪問 com.google.common.reflect.
ypeToken
[ERROR] 找不到 com.google.common.reflect.TypeToken 的類文件
[ERROR] /D:/s_book/Spring Cloud/codes/04/4.2/first-ribbon-client/src/main/java/org/crazyit/cloud/MyPingTest.java:[15,17] 找不到符號
[ERROR] 符號: 變量 ConfigurationManager
解決方法,使用 eclispe 或者修改 pom.xml,修改后的 pom.xml 內容如下:
dependencies
dependency
groupId com.netflix.ribbon /groupId
artifactId ribbon-core /artifactId
version 2.2.2 /version
/dependency
dependency
groupId com.netflix.ribbon /groupId
artifactId ribbon-loadbalancer /artifactId
version 2.2.2 /version
/dependency
dependency
groupId com.netflix.archaius /groupId
artifactId archaius-core /artifactId
version 0.7.5 /version
/dependency
dependency
groupId commons-configuration /groupId
artifactId commons-configuration /artifactId
version 1.9 /version
/dependency
dependency
groupId com.netflix.ribbon /groupId
artifactId ribbon-httpclient /artifactId
version 2.2.2 /version
/dependency
dependency
groupId com.google.guava /groupId
artifactId guava /artifactId
version 18.0 /version
/dependency
/dependencies
暫時不知道原因,估計是 eclipse 的 Maven 插件有問題,自動引入許多依賴。
讀到這里,這篇“如何構建 Ribbon 程序”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注丸趣 TV 行業資訊頻道。
正文完