springboot?去掉netflix?禁用Eureka的解決方法
報(bào)錯(cuò)
如果你接手別人的項(xiàng)目,啟動(dòng)的時(shí)候會(huì)一直報(bào)這個(gè)錯(cuò):發(fā)現(xiàn)有netflix,eureka相關(guān)字眼,
2023-09-13 16:25:47.875 [] [] [main] ERROR com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient -Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/'}
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
...
2023-09-13 16:25:47.875 [] [] [main] ERROR
com.netflix.discovery.shared.transport.TransportException:
Cannot execute request on any known server
但你項(xiàng)目只是一個(gè)簡(jiǎn)單的springboot項(xiàng)目,不是微服務(wù)(因?yàn)樯厦孢@些都是微服務(wù)相關(guān)組件)。你想去掉netflix相關(guān)組件,或者禁用eureka。
解決方法
方法一:去掉maven依賴(lài)
報(bào)上面的錯(cuò),通常是因?yàn)閜om文件里有eureka的依賴(lài)。
pom.xml里注釋掉下面這個(gè)依賴(lài),注釋完記得reload一下maven(右上角會(huì)出現(xiàn)刷新圖標(biāo))
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>去掉maven依賴(lài)后,項(xiàng)目中可能會(huì)有一些報(bào)錯(cuò)。
例如啟動(dòng)類(lèi),需要注釋掉@EnableEurekaClient
@SpringBootApplication
//@EnableEurekaClient
public class Application {}還有可能使用到了eureka的一些類(lèi),例如我項(xiàng)目里用到了aop的aspectj。
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; @Aspect @Pointcut(value = "execution(public * com.alibaba.yun.controller..*Controller.*(..))")
可以引入springboot的aop依賴(lài)。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>方法二:直接在application配置文件里禁用eureka(偷懶方法)
如果你只是簡(jiǎn)單維護(hù)別人的項(xiàng)目,并不想像上面那樣動(dòng)靜太大,那就直接用這個(gè)偷懶的辦法,直接在配置文件禁用eureka即可。
# 是否將自己注冊(cè)到 Eureka-Server 中,默認(rèn)true eureka.client.register-with-eureka=false # 是否需要拉取服務(wù)信息,默認(rèn)true eureka.client.fetch-registry=false
方法三:檢查eureka配置的地址是否正確(確實(shí)需要使用eureka)
如果你確實(shí)需要使用eureka,那就配置eureka正確的地址即可(問(wèn)同事要)。
# 則在Eureka服務(wù)發(fā)現(xiàn)應(yīng)該配置為:
# http://127.0.0.1:8080/eureka/
server.port: 8080
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/因?yàn)槲疫@篇文章是如何禁用eureka,所以不在此方法過(guò)多展開(kāi)。
=====================分割線(xiàn)=========================
文章到此已經(jīng)結(jié)束,以下是紫薯布丁
# 則在Eureka服務(wù)發(fā)現(xiàn)應(yīng)該配置為:
# http://127.0.0.1:8080/eureka/
server.port: 8080
eureka.client.serviceUrl.defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
# 是否將自己注冊(cè)到 Eureka-Server 中,默認(rèn)true
eureka.client.register-with-eureka=false
# 是否需要拉取服務(wù)信息,默認(rèn)true
eureka.client.fetch-registry=false
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
@Pointcut(value = "execution(public * com.alibaba.yun.controller..*Controller.*(..))")
@SpringBootApplication
//@EnableEurekaClient
public class Application {}
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>2023-09-13 16:25:47.875 [] [] [main] ERROR com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient -Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/'}
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
2023-09-13 16:25:47.875 [] [] [main] ERROR
com.netflix.discovery.shared.transport.TransportException:
Cannot execute request on any known server
到此這篇關(guān)于springboot 去掉netflix 禁用Eureka的文章就介紹到這了,更多相關(guān)springboot 禁用Eureka內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中-jar命令參數(shù)設(shè)置的完整指南
這篇文章主要為大家詳細(xì)介紹了Java中-jar命令參數(shù)設(shè)置有哪些分類(lèi)以及如何設(shè)置,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2026-03-03
IntelliJ IDEA 2020 安裝和常用配置(推薦)
這篇文章主要介紹了IntelliJ IDEA 2020 安裝和常用配置(推薦),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Spring事務(wù)管理下synchronized鎖失效問(wèn)題的解決方法
這篇文章主要給大家介紹了關(guān)于Spring事務(wù)管理下synchronized鎖失效問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-03-03
JAVA裝飾者模式(從現(xiàn)實(shí)生活角度理解代碼原理)
裝飾者模式可以動(dòng)態(tài)地給一個(gè)對(duì)象添加一些額外的職責(zé)。就增加功能來(lái)說(shuō),Decorator模式相比生成子類(lèi)更為靈活。這篇文章主要介紹了JAVA裝飾者模式的相關(guān)資料,需要的朋友可以參考下2016-12-12
關(guān)于maven本地倉(cāng)庫(kù)的配置方式
這篇文章主要介紹了關(guān)于maven本地倉(cāng)庫(kù)的配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06

