springcloud zookeeper注册中心,在客服端用restTemplate 访问,第一次访问正常,第二次以后都是失败

springcloud zookeeper注册中心,在客服端用restTemplate 访问,第一次访问正常,第二次以后都是失败:

配置以及主要代码如下:

服务端:

配置:
server.port=8082
spring.application.name=service-zookeeper
spring.cloud.zookeeper.discovery.register=true
spring.cloud.zookeeper.discovery.enabled=true
spring.cloud.zookeeper.discovery.root=/spring-cloud-service
spring.cloud.zookeeper.connect-string=cdh01.com:2181,cdh02.com:2181,cdh03.com:2181

java:

@RequestMapping(value ="/index")
    @ResponseBody
    public AjaxView index(@RequestBody String jsoninfo,HttpServletRequest request, HttpServletResponse response){
    。。。
}

客户端:

server.port=8081
spring.application.name=getway-zookeeper
spring.cloud.zookeeper.discovery.register=false
spring.cloud.zookeeper.discovery.enabled=true
spring.cloud.zookeeper.discovery.root=/spring-cloud-service
spring.cloud.zookeeper.connect-string=cdh01.com:2181,cdh02.com:2181,cdh03.com:2181
spring.cloud.zookeeper.dependencies.service-zookeeper.required=true
spring.cloud.zookeeper.dependencies.service-zookeeper.path=/service-zookeeper
spring.cloud.zookeeper.dependencies.service-zookeeper.loadBalancerType=ROUND_ROBIN
feign.hystrix.enabled=true

JAVA代码:

    @RequestMapping(value ="/api/{service_name}/{interface_name}")
    @ResponseBody
    public String getApiSend(
            @RequestBody String jsoninfo,
            @PathVariable String service_name,
            @PathVariable String interface_name) {

        String get_url ="http://"+service_name+"/"+interface_name;
        return   backService.getApiSend(jsoninfo,get_url);
    }

都启动成功后,第一次访问正常,第二次访问就报错了,报错提示没有找到服务列表,但是服务列表确实打印出来了。如下:
No up servers available from load balancer ,因为这个提示,没有服务,后续就报错空指针了。但是确实有服务查询到。而且DEBUG也打印出来了。

2019-05-19 14:37:55.547  WARN 164828 --- [nio-8081-exec-9] com.netflix.loadbalancer.RoundRobinRule  : No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=service-zookeeper,current list of Servers=[zhucj:8082],Load balancer stats=Zone stats: {unknown=[Zone:unknown; Instance count:1;   Active connections count: 0;    Circuit breaker tripped count: 0;   Active connections per server: 0.0;]
},Server stats: [[Server:zhucj:8082;    Zone:UNKNOWN;   Total Requests:0;   Successive connection failure:0;    Total blackout seconds:0;   Last connection made:Thu Jan 01 08:00:00 CST 1970;  First connection made: Thu Jan 01 08:00:00 CST 1970;    Active Connections:0;   total failure count in last (1000) msecs:0; average resp time:0.0;  90 percentile resp time:0.0;    95 percentile resp time:0.0;    min resp time:0.0;  max resp time:0.0;  stddev resp time:0.0]
]}ServerList:org.springframework.cloud.zookeeper.discovery.ZookeeperServerList@28667be9
[DEBUG][2019/05/1914:37:55549 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)]
Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException
[DEBUG][2019/05/1914:37:55552 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)]
Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException
[DEBUG][2019/05/1914:37:55555 ][org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136)]
Resolving exception from handler [public java.lang.String com.example.demo.controller.PageController.getApiSend(java.lang.String,java.lang.String,java.lang.String)]: java.lang.NullPointerException
[DEBUG][2019/05/1914:37:55558 ][org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:993)]
Could not complete request
java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:192)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3931)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4806)
    at com.netflix.loadbalancer.LoadBalancerStats.getServerStats(LoadBalancerStats.java:175)
    at com.netflix.loadbalancer.LoadBalancerStats.getSingleServerStat(LoadBalancerStats.java:362)
    at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:73)
    at com.netflix.loadbalancer.AvailabilityPredicate.apply(AvailabilityPredicate.java:35)
    at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:52)
    at com.netflix.loadbalancer.CompositePredicate.apply(CompositePredicate.java:40)
    at com.netflix.loadbalancer.AvailabilityFilteringRule.choose(AvailabilityFilteringRule.java:86)
    at org.springframework.cloud.zookeeper.discovery.dependency.DependenciesBasedLoadBalancer.chooseServer(DependenciesBasedLoadBalancer.java:64)
    at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration$1.chooseServerByServiceIdOrDefault(DependencyRibbonAutoConfiguration.java:72)
    at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRibbonAutoConfiguration$1.getServer(DependencyRibbonAutoConfiguration.java:65)
    at org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.choose(RibbonLoadBalancerClient.java:76)
    at org.springframework.cloud.client.loadbalancer.InterceptorRetryPolicy.canRetry(InterceptorRetryPolicy.java:53)
    at org.springframework.retry.support.RetryTemplate.canRetry(RetryTemplate.java:375)
    at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:278)
    at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:180)
    at org.springframework.cloud.client.loadbalancer.RetryLoadBalancerInterceptor.intercept(RetryLoadBalancerInterceptor.java:67)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at org.springframework.cloud.zookeeper.discovery.dependency.DependencyRestTemplateAutoConfiguration$1.intercept(DependencyRestTemplateAutoConfiguration.java:67)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:92)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:76)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:723)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:680)
    at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:466)
    at com.example.demo.util.WebUtil.SendPost(WebUtil.java:86)
    at com.example.demo.service.BackService.getApiSend(BackService.java:18)
    at com.example.demo.controller.PageController.getApiSend(PageController.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158)
    at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126)
    at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:90)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1468)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
[DEBUG][2019/05/1914:37:55574 ][org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:104)]
Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@46dfd3ba
2019-05-19 14:37:55.585 ERROR 164828 --- [nio-8081-exec-9] 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.NullPointerException] with root cause

请帮忙看看,谢谢。

1个回答

之前项目遗留的JAR包问题,重新创建一个干净的项目就可以了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问