springboot?去掉netflix?禁用Eureka的解決方法
報錯
如果你接手別人的項目,啟動的時候會一直報這個錯:發(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
但你項目只是一個簡單的springboot項目,不是微服務(wù)(因為上面這些都是微服務(wù)相關(guān)組件)。你想去掉netflix相關(guān)組件,或者禁用eureka。
解決方法
方法一:去掉maven依賴
報上面的錯,通常是因為pom文件里有eureka的依賴。
pom.xml里注釋掉下面這個依賴,注釋完記得reload一下maven(右上角會出現(xiàn)刷新圖標(biāo))
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>去掉maven依賴后,項目中可能會有一些報錯。
例如啟動類,需要注釋掉@EnableEurekaClient
@SpringBootApplication
//@EnableEurekaClient
public class Application {}還有可能使用到了eureka的一些類,例如我項目里用到了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依賴。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>方法二:直接在application配置文件里禁用eureka(偷懶方法)
如果你只是簡單維護(hù)別人的項目,并不想像上面那樣動靜太大,那就直接用這個偷懶的辦法,直接在配置文件禁用eureka即可。
# 是否將自己注冊到 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正確的地址即可(問同事要)。
# 則在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/因為我這篇文章是如何禁用eureka,所以不在此方法過多展開。
=====================分割線=========================
文章到此已經(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/
# 是否將自己注冊到 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java任意長度byte數(shù)組轉(zhuǎn)換為int數(shù)組的方法
這篇文章主要給大家介紹了關(guān)于Java任意長度byte數(shù)組轉(zhuǎn)換為int數(shù)組的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者使用Java具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
SpringMVC中的ResourceUrlProviderExposingInterceptor詳解
這篇文章主要介紹了SpringMVC中的ResourceUrlProviderExposingInterceptor詳解,ResourceUrlProviderExposingInterceptor是Spring MVC的一個HandlerInterceptor,用于向請求添加一個屬性,需要的朋友可以參考下2023-12-12
SpringBoot+SseEmitter和Vue3+EventSource實(shí)現(xiàn)實(shí)時數(shù)據(jù)推送
本文主要介紹了SpringBoot+SseEmitter和Vue3+EventSource實(shí)現(xiàn)實(shí)時數(shù)據(jù)推送,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-03-03
SpringBoot 監(jiān)聽Redis鍵過期事件(過期監(jiān)聽)
Redis鍵過期事件是SpringBoot中常用的緩存失效通知方式,通過配置可以監(jiān)聽特定鍵的過期事件,具有一定的參考價值,感興趣的可以了解一下2024-12-12
java中pdf轉(zhuǎn)圖片的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄猨ava中pdf轉(zhuǎn)圖片的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12

