搭建一個SpringCloud項目,通過Feign請求Eureka註冊中心其它服務實例,但是無論如何服務就是不去Eureka上註冊!!!後來經過數小心的排查,最終發現是Eureka—Client依賴添加錯誤造成的,這個問題解決超時。雖然使用SpringCloud和SpringBoot高集成依賴架構給我們帶來了很多方便,但由於內部版本複雜,我們在日常使用中一定要看仔細了再用,否則會出現各種莫名其妙的問題,拖慢開發進度。
Eureka-Client依賴李鬼還是李逵?
李鬼:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
李逵:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
噁心的是這倆玩意兒還能同時存在!!!
放一張細節圖:
更換依賴後問題解決!服務Eureka註冊成功且實現了通過實例名稱調用。
Tips:
在使用spring-cloud-netflix-eureka-client無法註冊Eureka上後,添加了Eureka-Server的依賴後註冊中心竟然神奇的出現了我們要註冊的服務!!!當我要通過Feign進行服務間通信時問題又來了。
com.netflix.client.ClientException: Load balancer does not have available server for client: helloservice
他孃的什麼鬼,我的服務明明都在Eureka上註冊,爲什麼不能夠實現服務間通信?
我的Eureka-Server依賴如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
</dependency>
而真正的Eureka-Server依賴如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
使用錯的東西也能註冊成功,但是無法實現通信,問題有待探討。
Pom依賴是特別細節的東西,大家在實際生產中一定要注意了。