当前位置:网站首页>Feignclient reported an error npe:null

Feignclient reported an error npe:null

2022-06-25 05:38:00 wisdommee

FeignClient Report errors NPE:null

I've been writing about spring cloud Micro service project of , An interface was added to the consumer yesterday , The result is wrong NPE, After analysis, it is found that springboot No automatic injection , The following is the analysis and solution of my problem

Error details

java.lang.NullPointerException: null at xxx.loginconsumer.controller.PostLoginController.updateBlockStates(PostLoginController.java:123) ~[classes!/:0.1.9] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.12.jar!/:5.3.12] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.12.jar!/:5.3.12] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.12.jar!/:5.3.12] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.12.jar!/:5.3.1

Code details

Controller

@PostMapping(value = "/block-user")
private ResultMessage<String> updateBlockStates(@RequestParam("user_id") String userId, @RequestParam("block") Boolean block){
    
    ...
}

Question why

I didn't notice that the method was written by me private 了 , Lead to springboot Unable to inject automatically , Led to NPE

resolvent

take private Change it to public, Perfect solution

@PostMapping(value = "/block-user")
public ResultMessage<String> updateBlockStates(@RequestParam("user_id") String userId, @RequestParam("block") Boolean block){
    
    ...
}
原网站

版权声明
本文为[wisdommee]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202210503492701.html