记一次低级错误:feign.FeignException: status 404 reading XXXClient#XXMethod(Long)

五一假期在家愉快的撸代码,本来喝着雪碧唱着歌,吹着小风享受惬意的生活,谁知道一个Bug从天而降,有Bug不怕,找四阿哥呀(专治八阿哥);于是开始了漫长的解决bug之旅。

feign.FeignException: status 404 reading XXXXClient#XXXXMethod(Long)

	at feign.FeignException.errorStatus(FeignException.java:62)
	at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
	at com.sun.proxy.$Proxy97.querySpuDetailBySpuId(Unknown Source)
	at XXXX(IndexService.java:41)
	at XXXX(ElasticsearchTest.java:63)
	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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

因为涉及到FeignClient调用问题,就先从FeignClient接口入手吧,查看出错的接口有没有错误,期间在网上找到了同样这种报错的同学,有的是忘了写@RequestMapping的,有的是忘了给Controller中的Service添加@Autowired的,检查了一下,发现都没有问题。这里就要强调细心的问题了,是吧,强调了还忘,同学们长点心吧,咳咳,不好意思,走错片场了。
然后呢就去找第二个解决方案,发现报错中有TimeOut的字样,于是看一下是不是因为熔断机制出了错呀,然后在网上找了一下,发现熔断机制就需要配置如下配置:

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMillisecond: 10000 # 熔断超时时长:10000ms

我这里也有呀。
又输一局,再来。随后我又把设计报错的方法的Controller、Service以及Pojo都梳理了一遍,还是没有发现问题。无奈,只能跟进去一个一个查看了,好在涉及的数据不多,只有不到二百个,前面我在跟的时候只跟了几个发现没有问题,于是放心大胆的放行了,可是每次都报错,也只有全跟了,事实证明,笨方法还是好用,在快要跟完近200个数据的时候,发现了报错。
原因终于发现了,是因为两个表中的数据不对应,查询之后没有做判断,直接拿来用在第二个表的查询上,直接导致了空指针的异常。可以说这个错误是非常低级的了,挂在这里游街吧,提醒以后别再犯了。
处理这个BUG也提醒了我,Feign报错可能是本身服务提供方的方法没有写好。

你可能感兴趣的:(Java)