使用RestTemplate 请求某个服务 No servers available for service的问题解决方法

2024-12-12 10:34:01.492  WARN 1 --- [oundedElastic-4] o.s.c.l.core.RoundRobinLoadBalancer      : No servers available for service: XXXXXXXXXXXXX
java.lang.IllegalStateException: No instances available for 10.142.244.11
    at org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient.execute(BlockingLoadBalancerClient.java:79)
    at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:56)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
    at com.enrising.ctsc.common.security.component.AiResourceServerAutoConfiguration.lambda$lbRestTemplate$0(AiResourceServerAutoConfiguration.java:51)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
    at com.enrising.ctsc.purchase.filesystem.util.DfsUtilsService.downloadForStream(DfsUtilsService.java:63)
    at com.enrising.ctsc.purchase.filesystem.util.DfsUtilsService.downloadForStream(DfsUtilsService.java:38)
    at com.enrising.ctsc.purchase.filesystem.service.impl.FilingServiceImpl.historyFileUploadTask(FilingServiceImpl.java:397)
    at com.enrising.ctsc.purchase.filesystem.service.impl.FilingServiceImpl$$FastClassBySpringCGLIB$$56694f8.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at com.enrising.ctsc.purchase.filesystem.service.impl.FilingServiceImpl$$EnhancerBySpringCGLIB$$fccef0f.historyFileUploadTask(<generated>)
    at com.enrising.ctsc.purchase.filesystem.controller.FilingController.historyFileUploadTask(FilingController.java:78)
    at com.enrising.ctsc.purchase.filesystem.controller.FilingController$$FastClassBySpringCGLIB$$e3e5b0f6.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:64)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:57)

一:由于我在某个服务中调用一个服务,结果服务报错No servers available for service: + ip地址

因为我这个服务是个微服务,然后我直接注入使用的 restTemplate对象。导致最终调用时候是在自己应用里面找对应的ip服务。默认认为自己应用中微服务之间的调用。

修改后的代码为:直接新建一个new RestTemplate()解决问题。

之前:网上看得案例包括有自己微服务调用需要将你调用的ip地址修改为对应的服务的注册名称才能调用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值