天天看點

Spreing Cloud(三):Spring Cloud服務注冊的坑(服務無法注冊到注冊中心)

題記:這個是在自己搭建項目時突然發現搭建的項目啟動正常,但是在注冊中心發現不了啟動的服務。

運作環境:idea:2018.3.2

原因:一句話就是版本不對。

分析:

當你使用idea預設加載的jar時《parent》版本是這樣的,這是最新的版本,要驗證可以去maven官網查詢一下

Spreing Cloud(三):Spring Cloud服務注冊的坑(服務無法注冊到注冊中心)

但是你可以去查詢一下下邊的依賴,這個依賴卻不是最新的,而是2.0以前的,但是這也是idea預設加載進來的。當你在使用注解時添加的也是2.0以前的

idea使用注解@EnableDiscoveryClient 等自動導入的依賴也是2.0.0以下版本使用的依賴這種的 

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-client</artifactId>
            <version>2.1.0.RC3</version>
        </dependency>
           

解決:

把上邊的版本改為下圖即可:看到有什麼差別嗎

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>
           

繼續閱讀