学习 spring cloud 时错误笔记

最近在慢慢学习cloud的相关知识,会把碰见的一些问题记录下来。
对照学习的参考链接:【程序猿DD】Spring Cloud构建微服务架构系列,持续更新~](http://bbs.springcloud.com.cn/d/1-dd-spring-cloud)
在 spring cloud 入门时避免不了出现大大小小的问题,我就把我遇到的问题和解决方法贴在下面:

  • 1, Connection refused: connect Cannot execute request on any known server :无法在任何已知服务器上执行请求
    出现这个问题你就要看看 Eureka 项目和子项目中的 defaultZone 是否相同

学习 spring cloud 时错误笔记_第1张图片

  • 2、在默认设置下,Eureka服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为。 禁止方式如下
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

如果不禁止会报一下错误:

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
 2018  WARN 6864 --- [main] RetryableEurekaHttpClient: Request execution failure

2018 ERROR 6864 --- [main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_UNKNOWN/DESKTOP-MQ8D0C9:8761 - was unable to refresh its cache! status = Cannot execute request on any known server
  • 3 , com.netflix.hystrix.exception.HystrixRuntimeException: api timed-out and no fallback available. 超时问题
    或者 Read timed-out 错误.在 yml中加入:

#######解决超时问题

hystrix:
command:
  default:
   execution:
    isolation:
     thread:
      timeoutInMilliseconds: 10000

或者:

#######解决超时问题
hystrix:
metrics:
  enabled: true
command:
  default:
   execution:
    isolation:
     thread:
       timeoutInMilliseconds: 12000

两者选其一都可以解决,亲测有效!

4, 遇到这样的错误:

  com.netflix.zuul.exception.ZuulException: Forwarding error
at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:
	at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:163) 
	at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:111) ~
	at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.ja
	at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequest(ZuulController.java:44) [spring-
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]
Caused by: com.netflix.client.ClientException: Load balancer does not have available server for client: api
	at com.netflix.loadbalancer.LoadBalancerContext.getServerFromLoadBalancer(LoadBalancerContext.java:483) ~[ribbon-loadbalancer-2.2.2.jar:2.2.2]

这是因为你省略了这个依赖:



    org.springframework.cloud
    spring-cloud-starter-eureka

zuul服务器要读取eureka注册的微服务,必须自己也要作为eureka的客户端,所以必定要配置eureka依赖。

5 ,遇到这样的异常

 2018-02-07 15:40:43.458 ERROR 21630 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.hxy.cloud.AppCenter]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525) ~[spring-
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-
Caused by:java.lang.IllegalStateException: Failed to introspect annotated methods on class 
org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:24
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:606) ~[spring-context-4.3.10.RELEASE.jar:
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_151]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_151]
	... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.embedded.FilterRegistrationBean
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_151]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_151]
	... 30 common frames omitted

遇到这样的错误只需要把:


    
        
            org.springframework.cloud
            spring-cloud-dependencies
            Brixton.RELEASE
            pom
            import
        
    

改为:


    
        
            org.springframework.cloud
            spring-cloud-dependencies
           
             Dalston.SR3
            pom
            import
        
    

即可!!! 因为使用的 spring boot版本不同!

写在最后

加wx,获得更多关于Spring Cloud高级视频

学习 spring cloud 时错误笔记_第2张图片

你可能感兴趣的:(异常,spring,cloud,笔记)