采用springcloud-alibaba整合rabbion使用DiscoveryClient调用restful时遇到的一个问题,报错如下:

 D:\javaDevlepTool\java1.8\jdk1.8\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\javaDevlepTool\IDEA\IntelliJ IDEA 2018.2.8\lib\idea_rt.jar=57241:D:\javaDevlepTool\IDEA\IntelliJ IDEA 2018.2.8\bin" -Dfile.encoding=UTF-8 -classpath D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\charsets.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\deploy.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\access-bridge-64.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\cldrdata.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\dnsns.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\jaccess.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\jfxrt.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\localedata.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\nashorn.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\sunec.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\sunjce_provider.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\sunmscapi.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\sunpkcs11.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\ext\zipfs.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\javaws.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\jce.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\jfr.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\jfxswt.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\jsse.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\management-agent.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\plugin.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\resources.jar;D:\javaDevlepTool\java1.8\jdk1.8\jre\lib\rt.jar;D:\drawnblue\springcloud-alibaba\user\target\classes;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-starter-web\2.1.6.RELEASE\spring-boot-starter-web-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-starter-json\2.1.6.RELEASE\spring-boot-starter-json-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\javaEnvironment\repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-starter-tomcat\2.1.6.RELEASE\spring-boot-starter-tomcat-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.21\tomcat-embed-core-9.0.21.jar;D:\javaEnvironment\repo\org\apache\tomcat\embed\tomcat-embed-el\9.0.21\tomcat-embed-el-9.0.21.jar;D:\javaEnvironment\repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.21\tomcat-embed-websocket-9.0.21.jar;D:\javaEnvironment\repo\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;D:\javaEnvironment\repo\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\javaEnvironment\repo\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\javaEnvironment\repo\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;D:\javaEnvironment\repo\org\springframework\spring-web\5.1.8.RELEASE\spring-web-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-beans\5.1.8.RELEASE\spring-beans-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-webmvc\5.1.8.RELEASE\spring-webmvc-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-aop\5.1.8.RELEASE\spring-aop-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-context\5.1.8.RELEASE\spring-context-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-expression\5.1.8.RELEASE\spring-expression-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;D:\javaEnvironment\repo\org\springframework\spring-core\5.1.8.RELEASE\spring-core-5.1.8.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\spring-jcl\5.1.8.RELEASE\spring-jcl-5.1.8.RELEASE.jar;D:\drawnblue\springcloud-alibaba\common\target\classes;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-starter-alibaba-nacos-discovery\0.9.0.RELEASE\spring-cloud-starter-alibaba-nacos-discovery-0.9.0.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-alibaba-nacos-discovery\0.9.0.RELEASE\spring-cloud-alibaba-nacos-discovery-0.9.0.RELEASE.jar;D:\javaEnvironment\repo\com\alibaba\nacos\nacos-client\1.0.0\nacos-client-1.0.0.jar;D:\javaEnvironment\repo\com\alibaba\nacos\nacos-common\1.0.0\nacos-common-1.0.0.jar;D:\javaEnvironment\repo\commons-io\commons-io\2.2\commons-io-2.2.jar;D:\javaEnvironment\repo\org\apache\commons\commons-lang3\3.8.1\commons-lang3-3.8.1.jar;D:\javaEnvironment\repo\com\alibaba\nacos\nacos-api\1.0.0\nacos-api-1.0.0.jar;D:\javaEnvironment\repo\com\alibaba\fastjson\1.2.47\fastjson-1.2.47.jar;D:\javaEnvironment\repo\com\google\guava\guava\19.0\guava-19.0.jar;D:\javaEnvironment\repo\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;D:\javaEnvironment\repo\io\prometheus\simpleclient\0.5.0\simpleclient-0.5.0.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-commons\2.1.2.RELEASE\spring-cloud-commons-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\security\spring-security-crypto\5.1.5.RELEASE\spring-security-crypto-5.1.5.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-context\2.1.2.RELEASE\spring-cloud-context-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-starter-netflix-ribbon\2.1.2.RELEASE\spring-cloud-starter-netflix-ribbon-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-starter\2.1.2.RELEASE\spring-cloud-starter-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;D:\javaEnvironment\repo\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;D:\javaEnvironment\repo\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-netflix-ribbon\2.1.2.RELEASE\spring-cloud-netflix-ribbon-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-netflix-archaius\2.1.2.RELEASE\spring-cloud-netflix-archaius-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\cloud\spring-cloud-starter-netflix-archaius\2.1.2.RELEASE\spring-cloud-starter-netflix-archaius-2.1.2.RELEASE.jar;D:\javaEnvironment\repo\com\netflix\archaius\archaius-core\0.7.6\archaius-core-0.7.6.jar;D:\javaEnvironment\repo\com\google\code\findbugs\jsr305\3.0.1\jsr305-3.0.1.jar;D:\javaEnvironment\repo\commons-configuration\commons-configuration\1.8\commons-configuration-1.8.jar;D:\javaEnvironment\repo\com\netflix\ribbon\ribbon\2.3.0\ribbon-2.3.0.jar;D:\javaEnvironment\repo\com\netflix\ribbon\ribbon-transport\2.3.0\ribbon-transport-2.3.0.jar;D:\javaEnvironment\repo\io\reactivex\rxnetty-contexts\0.4.9\rxnetty-contexts-0.4.9.jar;D:\javaEnvironment\repo\io\reactivex\rxnetty-servo\0.4.9\rxnetty-servo-0.4.9.jar;D:\javaEnvironment\repo\com\netflix\hystrix\hystrix-core\1.5.18\hystrix-core-1.5.18.jar;D:\javaEnvironment\repo\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;D:\javaEnvironment\repo\javax\inject\javax.inject\1\javax.inject-1.jar;D:\javaEnvironment\repo\io\reactivex\rxnetty\0.4.9\rxnetty-0.4.9.jar;D:\javaEnvironment\repo\com\netflix\ribbon\ribbon-core\2.3.0\ribbon-core-2.3.0.jar;D:\javaEnvironment\repo\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;D:\javaEnvironment\repo\com\netflix\ribbon\ribbon-httpclient\2.3.0\ribbon-httpclient-2.3.0.jar;D:\javaEnvironment\repo\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;D:\javaEnvironment\repo\org\apache\httpcomponents\httpclient\4.5.9\httpclient-4.5.9.jar;D:\javaEnvironment\repo\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;D:\javaEnvironment\repo\com\sun\jersey\jersey-client\1.19.1\jersey-client-1.19.1.jar;D:\javaEnvironment\repo\com\sun\jersey\jersey-core\1.19.1\jersey-core-1.19.1.jar;D:\javaEnvironment\repo\javax\ws\rs\jsr311-api\1.1.1\jsr311-api-1.1.1.jar;D:\javaEnvironment\repo\com\sun\jersey\contribs\jersey-apache-client4\1.19.1\jersey-apache-client4-1.19.1.jar;D:\javaEnvironment\repo\com\netflix\servo\servo-core\0.12.21\servo-core-0.12.21.jar;D:\javaEnvironment\repo\com\netflix\netflix-commons\netflix-commons-util\0.3.0\netflix-commons-util-0.3.0.jar;D:\javaEnvironment\repo\com\netflix\ribbon\ribbon-loadbalancer\2.3.0\ribbon-loadbalancer-2.3.0.jar;D:\javaEnvironment\repo\com\netflix\netflix-commons\netflix-statistics\0.1.1\netflix-statistics-0.1.1.jar;D:\javaEnvironment\repo\io\reactivex\rxjava\1.3.8\rxjava-1.3.8.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-starter\2.1.6.RELEASE\spring-boot-starter-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot\2.1.6.RELEASE\spring-boot-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-autoconfigure\2.1.6.RELEASE\spring-boot-autoconfigure-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\org\springframework\boot\spring-boot-starter-logging\2.1.6.RELEASE\spring-boot-starter-logging-2.1.6.RELEASE.jar;D:\javaEnvironment\repo\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\javaEnvironment\repo\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\javaEnvironment\repo\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;D:\javaEnvironment\repo\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;D:\javaEnvironment\repo\org\slf4j\jul-to-slf4j\1.7.26\jul-to-slf4j-1.7.26.jar;D:\javaEnvironment\repo\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\javaEnvironment\repo\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar com.drawnblue.UserApplication
2019-08-20 21:49:16.138 INFO 2896 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$39244cdd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) . ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE) 2019-08-20 21:49:17.557 INFO 2896 --- [ main] com.drawnblue.UserApplication : No active profile set, falling back to default profiles: default
2019-08-20 21:49:18.392 INFO 2896 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=f26475a6-8ec9-369b-81c6-da54b33473b9
2019-08-20 21:49:18.422 INFO 2896 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$39244cdd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-08-20 21:49:18.758 INFO 2896 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8002 (http)
2019-08-20 21:49:18.793 INFO 2896 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-20 21:49:18.793 INFO 2896 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-20 21:49:18.974 INFO 2896 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-20 21:49:18.974 INFO 2896 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1390 ms
2019-08-20 21:49:21.276 WARN 2896 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-08-20 21:49:21.276 INFO 2896 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-08-20 21:49:21.284 WARN 2896 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-08-20 21:49:21.284 INFO 2896 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-08-20 21:49:21.600 INFO 2896 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-20 21:49:22.061 INFO 2896 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService
2019-08-20 21:49:22.344 INFO 2896 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8002 (http) with context path ''
2019-08-20 21:49:22.430 INFO 2896 --- [ main] o.s.c.a.n.registry.NacosServiceRegistry : nacos registry, user 192.168.179.1:8002 register finished
2019-08-20 21:49:22.434 INFO 2896 --- [ main] com.drawnblue.UserApplication : Started UserApplication in 11.304 seconds (JVM running for 13.348)
2019-08-20 21:49:27.223 INFO 2896 --- [nio-8002-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-08-20 21:49:27.225 INFO 2896 --- [nio-8002-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-08-20 21:49:27.238 INFO 2896 --- [nio-8002-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 13 ms
======================[org.springframework.cloud.alibaba.nacos.NacosServiceInstance@2bcfc07f, org.springframework.cloud.alibaba.nacos.NacosServiceInstance@291f102]
http://192.168.179.1:8011/userService/findById/{id}------targetUrl org.springframework.web.client.RestTemplate@3910fe11
2019-08-20 21:49:29.040 INFO 2896 --- [nio-8002-exec-1] c.netflix.config.ChainedDynamicProperty : Flipping property: 192.168.179.1.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-08-20 21:49:29.096 INFO 2896 --- [nio-8002-exec-1] c.netflix.loadbalancer.BaseLoadBalancer : Client: 192.168.179.1 instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=192.168.179.1,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2019-08-20 21:49:29.107 INFO 2896 --- [nio-8002-exec-1] c.n.l.DynamicServerListLoadBalancer : Using serverListUpdater PollingServerListUpdater
2019-08-20 21:49:29.120 INFO 2896 --- [nio-8002-exec-1] c.n.l.DynamicServerListLoadBalancer : DynamicServerListLoadBalancer for client 192.168.179.1 initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=192.168.179.1,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:org.springframework.cloud.alibaba.nacos.ribbon.NacosServerList@623249f7
2019-08-20 21:49:29.175 ERROR 2896 --- [nio-8002-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: No instances available for 192.168.179.1] with root cause java.lang.IllegalStateException: No instances available for 192.168.179.1
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:119) ~[spring-cloud-netflix-ribbon-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.execute(RibbonLoadBalancerClient.java:99) ~[spring-cloud-netflix-ribbon-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor.intercept(LoadBalancerInterceptor.java:58) ~[spring-cloud-commons-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:735) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:338) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at com.drawnblue.usercontroller.UserController.findById2(UserController.java:41) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) ~[spring-webmvc-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:109) ~[spring-web-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587) [tomcat-embed-core-9.0.21.jar:9.0.21]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.21.jar:9.0.21]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_161]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_161]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.21.jar:9.0.21]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]

主要代码如下:

package com.drawnblue;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate; @SpringBootApplication
@EnableDiscoveryClient
public class UserApplication { public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
} @Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

  conotroller

 package com.drawnblue.usercontroller;

 import com.drawnblue.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate; import java.util.List; @RestController
public class UserController {
@Autowired
private RestTemplate restTemplate;
@Autowired
private DiscoveryClient discoveryClient;
@GetMapping("/test/{id}")
public User findById(@PathVariable Long id) {
System.out.println("調用kaishi");
ResponseEntity<User> body = this.restTemplate.getForEntity("http://user-service/userService/findById/"+id, User.class);
System.out.println("調用完成");
return body.getBody();
}
@GetMapping("/getInstances")
public List<ServiceInstance> getInstances(){
return this.discoveryClient.getInstances("user-service");
}
@GetMapping("/test1/{id}")
public User findById2(@PathVariable Long id){
List<ServiceInstance> instances = discoveryClient.getInstances("user-service");
System.out.println("======================"+instances);
String targetURL = instances.stream()
.map(instance -> instance.getUri().toString()+"/userService/findById/{id}")
.findFirst().orElseThrow(()-> new IllegalArgumentException("当前没有实例")); System.out.println(targetURL+"------targetUrl"+" "+this.restTemplate);
ResponseEntity<User> body = this.restTemplate.getForEntity(targetURL,User.class,1);
return body.getBody();
}
}

根据日志中的url和传值id=1直接在浏览器都能返回,但是调用改接口就报错:

最终发现是因为

 @LoadBalanced
的原因。
加了了注解 @LoadBalanced 之后,我们的r estTemplate 会走这个类RibbonLoadBalancerClient,断点进入了如下的页面,serverid必须是我们访问的服务名称 ,当我们直接输入ip的时候获取的server是null,就会抛出异常
当我把这个注释掉以后,重启一下,再去访问ok.
再次访问:

手写的随机负载均衡代码如下:

     @RequestMapping("/getUserT/{id}")
public User getUserByRestTemplate(@PathVariable("id") String id){
List<ServiceInstance> list = this.discoveryClient.getInstances("user-service");
List<String> targetUrls = list.stream().map(serviceInstance -> serviceInstance.getUri().toString()).collect(Collectors.toList());
int i = new Random().nextInt(targetUrls.size());
System.out.println("-------"+targetUrls.get(i).toString());
ResponseEntity<User> response = restTemplate.getForEntity(targetUrls.get(i)+"/test/{id}",User.class,id);
return response.getBody();
}

运行日志:

说明实现了随机,并没有轮询访问

												

springcloud-alibaba手写负载均衡的坑,采用restTemplate,不能添加@loadbalanced注解,否则采用了robbin的更多相关文章

  1. 最适合新手入门的SpringCloud教程 6—Ribbon负载均衡「F版本」

    SpringCloud版本:Finchley.SR2 SpringBoot版本:2.0.3.RELEASE 源码地址:https://gitee.com/bingqilinpeishenme/Java ...

  2. SpringCloud学习(4)——Ribbon负载均衡

    Ribbon概述 SpringCloud Ribbon是基于Netflix Ribbon实现的一套客户端负载均衡工具. 简单的说, Ribbon是Netflix发布的开源项目, 主要功能是提供客户端软 ...

  3. springcloud 之Ribbon客户端负载均衡配置使用

    pom.xml添加配置说明:这里服务注册与发现用的是Eureka,所以消费者端需要引入eureka,使用EurekaClient来调用服务 <dependency> <groupId ...

  4. 008 SpringCloud 学习笔记4-----Ribbon负载均衡

    1.Ribbon概述 实际环境中,我们往往会开启很多个itcast-service-provider的集群.此时我们获取的服务列表中就会有多个,到底该访问哪一个呢? Eureka中已经帮我们集成了负载 ...

  5. 【Spring Cloud 源码解读】之 【这也太神奇了,RestTemplate加上一个@LoadBalanced注解就能实现负载均衡!】

    前提概要: 前天,有个前端大佬问了我两个问题:为啥不引入Ribbon依赖就能使用Ribbon?为啥RestTemplate加上@LoadBalanced注解就能负载均衡了?我也表示很疑惑,而我自己其实 ...

  6. SpringCloud Ribbon组成和负载均衡规则

    Ribbon饥饿加载 默认情况下Ribbon是懒加载的.当服务起动好之后,第一次请求是非常慢的,第二次之后就快很多. 解决方式:开启饥饿加载 ribbon: eager-load: enabled: ...

  7. java框架之SpringCloud(4)-Ribbon&Feign负载均衡

    在上一章节已经学习了 Eureka 的使用,SpringCloud 也提供了基于 Eureka 负载均衡的两种方案:Ribbon 和 Feign. Ribbon负载均衡 介绍 SpringCloud ...

  8. SpringCloud系列之客户端负载均衡Netflix Ribbon

    1. 什么是负载均衡? 负载均衡是一种基础的网络服务,它的核心原理是按照指定的负载均衡算法,将请求分配到后端服务集群上,从而为系统提供并行处理和高可用的能力.提到负载均衡,你可能想到nginx.对于负 ...

  9. 使用TensorFlow的卷积神经网络识别自己的单个手写数字,填坑总结

    折腾了几天,爬了大大小小若干的坑,特记录如下.代码在最后面. 环境: Python3.6.4 + TensorFlow 1.5.1 + Win7 64位 + I5 3570 CPU 方法: 先用MNI ...

随机推荐

  1. windows 域控用户记住最后一次登录用户名

    1,记住最后一次登录用户名 运行 gpedit.msc命令 禁用设置

  2. 使用Kubespray在ubuntu上自动部署K8s1.9.0集群

    Kubespray 是 Kubernetes incubator 中的项目,目标是提供 Production Ready Kubernetes 部署方案,该项目基础是通过 Ansible Playbo ...

  3. 【SSM 项目】实战总结

           项目源代码

  4. 【PAT甲级】1065 A+B and C (64bit) (20 分)(大数溢出)

    题意: 输入三个整数A,B,C(long long范围内),输出是否A+B>C. trick: 测试点2包括溢出的数据,判断一下是否溢出即可. AAAAAccepted code: #defin ...

  5. 二十二、mysql 执行计划与存储引擎

    1.explain(执行计划)中涉及的各字段理解1.1) select_type列的取值及含义:    SIMPLE                 :简单的SELECT语句(不包括UNION操作或子 ...

  6. linux的压力测试工具

    只能用于http的测试工具: ab: 安装方法:yum install httpd-tools -y 使用:ab -c 1000 -n 10000 + ip            -c 为并发数,-n ...

  7. 树莓派4B踩坑指南 - (6)安装常用软件及相关设置

    安装软件 安装LibreOffice中文包 sudo apt-get install libreoffice-l10n-zh-cn sudo reboot 安装codeblocks并汉化: sudo ...

  8. IDEA工具java开发之 代码重构Refactor 重命名 删除移动复制 生成变量 抽取方法

    一.重命名 用shift + F6 或者右键单击 二.抽取方法 .三.生成变量 . 四.文件移动复制和删除 可以右键

  9. 「luogu3402」【模板】可持久化并查集

    「luogu3402」[模板]可持久化并查集 传送门 我们可以用一个可持久化数组来存每个节点的父亲. 单点信息更新和查询就用主席树多花 一个 \(\log\) 的代价来搞. 然后考虑如何合并两个点. ...

  10. MySQL报Too many connections

    错误信息 Exception in thread "main" java.sql.SQLNonTransientConnectionException: Data source r ...