java.lang.IllegalStateException: No instances available for localhost

在这里插入图片描述
Spring Cloud 使用RestTemplate进行服务调用时出现

java.lang.IllegalStateException: No instances available for localhost
at
org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient.execute(BlockingLoadBalancerClient.java:79)
~[spring-cloud-loadbalancer-3.0.3.jar:3.0.3] at
org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:56)
~[spring-cloud-commons-3.0.3.jar:3.0.3] at
org.springframework.http.client.InterceptingClientHttpRequest¥InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:93)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:77)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:334)
~[spring-web-5.3.7.jar:5.3.7] at
com.zero.userservices.service.impl.UserServiceImpl.templUser(UserServiceImpl.java:35)
~[classes/:na] at
com.zero.userservices.controller.UserController.templUser(UserController.java:39)
~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method) ~[na:1.8.0_212] at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
~[na:1.8.0_212] at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
~[na:1.8.0_212] at java.lang.reflect.Method.invoke(Method.java:498)
~[na:1.8.0_212] at
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1063)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
~[spring-webmvc-5.3.7.jar:5.3.7] at
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
~[spring-webmvc-5.3.7.jar:5.3.7] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
~[tomcat-embed-core-9.0.46.jar:4.0.FR] at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
~[spring-webmvc-5.3.7.jar:5.3.7] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
~[tomcat-embed-core-9.0.46.jar:4.0.FR] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
~[tomcat-embed-websocket-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
~[spring-web-5.3.7.jar:5.3.7] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
~[spring-web-5.3.7.jar:5.3.7] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
~[spring-web-5.3.7.jar:5.3.7] at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
~[spring-web-5.3.7.jar:5.3.7] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
~[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.coyote.AbstractProtocol¥ConnectionHandler.process(AbstractProtocol.java:893)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.tomcat.util.net.NioEndpoint¥SocketProcessor.doRun(NioEndpoint.java:1707)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[na:1.8.0_212] at
java.util.concurrent.ThreadPoolExecutor¥Worker.run(ThreadPoolExecutor.java:624)
[na:1.8.0_212] at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
[tomcat-embed-core-9.0.46.jar:9.0.46] at
java.lang.Thread.run(Thread.java:748) [na:1.8.0_212]

这个呢是因为服务注册到服务中心了,服务之间的调用就不是用地址来访问,而是用注册的服务名称来访问了
就是配置文件中spring.application.name属性

spring:
  application:
    name: zero-provider-001

在使用restTemplate访问的时候使用这个名字加端口访问,就是注册中心里面的这个:

在这里插入图片描述
在这里插入图片描述
不能用地址或者localhost访问,要写注册的服务名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水超涌也

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值