Exception笔记

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eOaRUUl7-1603719345148)(Exception笔记.assets\170.jpg)]

Author:高小昂

Since:2020年10月21日

Order:首字母A~Z

前言

学习不易,多记笔记;逆水行舟,就要用力!

​ ——鲁迅


上面那句话不是我说的。

​ ——鲁迅

一、AuthenticationFailureException

异常全限定名:com.rabbitmq.client.AuthenticationFailureException

1.1、ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.

  1. 场景:RabbitMQ
  2. 信息:使用认证机制拒绝登录。
  3. 解决方案:
    1. 不要用guest登录!!!!!
    2. 密码不对,重新校对去!

二、ClientException:

异常全限定名:com.netflix.client.ClientException

2.1、Load balancer does not have available server for client: FEIGN-SEARCH-01

  1. 场景:springCloud - Feign
  2. 信息:负载平衡器没有可用的服务器给客户端:FEIGN-SEARCH-01
  3. 你太快了,慢一点,待会再请求

三、FeignException

异常全限定名:feign.FeignException

3.1、$NotFound: [404] during [GET] to [http://FEIGN-SEARCH-01/costomer] [SearchClient#getPath()]: [{“timestamp”:“2020-10-22T13:37:29.003+00:00”,“status”:404,“error”:“Not Found”,“message”:"",“path”:"/costomer"}]

  1. 场景:springCloud - Feign
  2. 现象:前端页面显示500,后端异常为404
  3. 信息:SearchClient接口映射的访问路径与search模块的接口不一致
  4. 解决方法:修改接口映射访问路径

四、IllegalStateException

异常全限定名:java.lang.IllegalStateException

4.1、PathVariable annotation was empty on param 0

  1. 场景:springCloud - Feign 启动报错

  2. 信息:进行远程调用时,如果在client的接口映射中,参数是通过@PathVariable这种动态路径变量的形式来传递的,此时@PathVariable注解必须明确写明参数的名称!

  3. 解决方法举例:

    @GetMapping("/search/{id}")
    //                                    这里的括号必须写
    Customer getCustomerById(@PathVariable("id") Integer id);
    

4.2、Request caching is not available.Maybe you need to initialize the HystrixRequestContext?

  1. 场景:springCloud - Hystrix

  2. 信息:使用Hystrix的缓存功能时,未初始化一个对象:HystrixRequestContext

  3. 解决方案:配置一个HystrixRequestContext对象,为了保证所有的请求方法都可以利用Hystrix缓存功能,建议使用filter来配置。

    @WebFilter("/*")
    public class HystrixCacheContextFilter implements Filter {
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            //初始化HystrixRequestContext类,解决Hystrix缓存不可用的问题!
            //之所以在过滤器中进行初始化,是为了保证所有的请求方法都可以利用Hystrix缓存功能!
            HystrixRequestContext.initializeContext();
            chain.doFilter(request,response);
        }
    }
    

4.3、Service id not legal hostname (hostname_名)

  1. 场景:springCloud
  2. 信息:使用微服务spring cloud中的@FeignClient注解,定义的名称不能带下划线"_",属于非法字符
  3. 解决方案:修改yml文件中 spring.application.name 的值

五、TransportException

异常全限定名:com.netflix.discovery.shared.transport.TransportException

5.1、Cannot execute request on any known server

  1. 场景:springCloud微服务启动报错

  2. 信息:连接Eureka服务端地址不对。

  3. 解决方案:

    1. 查看yml文件配置

      # 注意缩进!注意缩进!注意缩进!
      eureka: 
        client: 
          # 是否将自己注册到 Eureka-Server 中,默认的为 true   registerWithEureka等同于register_with_eureka
          registerWithEureka: false
          # 是否需要拉取服务信息,默认未true       fetchRegistry等同于 fetch-registry
          fetchRegistry: false
      
    
    2. 查看连接Eureka服务端URL
    
    3. 去`maven仓库`中查看依赖包是否有问题
    

六、ZuulException

异常全限定名:com.netflix.zuul.exception.ZuulException

6.1、信息内容为空

  1. 场景:springCloud - Ribbon

  2. 现象:前端显示错误

    There was an unexpected error (type=Gateway Timeout, status=504)
    
  3. 解决方法:在yml中添加配置

    ribbon:
      ReadTimeout: 120000  #请求处理的超时时间
      ConnectTimeout: 30000  #请求连接的超时时间
    
  1. 解决方法:在yml中添加配置

    ribbon:
      ReadTimeout: 120000  #请求处理的超时时间
      ConnectTimeout: 30000  #请求连接的超时时间
    
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值