Failed to meta-introspect annotation interface org.springframework.web.bind.annotation.RequestBody:

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
云原生网关 MSE Higress,422元/月
注册配置 MSE Nacos/ZooKeeper,118元/月
简介: Failed to meta-introspect annotation interface org.springframework.web.bind.annotation.RequestBody:
今天遇到了调试了很久的bug,最后发现是个小问题,报异常如下:
Failed to meta-introspect annotation interface org.springframework.web.bind.annotation.RequestBody: java.lang.NullPointerException
log4j给出了空指针的提示,又观察到跟注解RequestBody有关,疑似josn转对象失败,造成空指针异常,但自己在代码块中打印出了转换对象的属性

然而在网页开发者工具中发现请求成功

2018122814580746.png

在debug过程中发现,json转换的对象其实是成功的,空指针其实指的是服务接口

2018122814580746.png

转而目标点从请求传送对象转到服务中来,应该是zookeeper和dubbo的问题,使用zookeeper的客户端连接后查看后发现,确实是缺少消费者(consumers)服务的注册,那么问题一定出现在消费者服务的逻辑中

2018122814580746.png

缺少消费者服务的注册,反复观察代码逻辑没有任何问题,springmvc.xml中的配置也没有问题,经过仔细观察,最终发现是注解Refence引用的不对,应该引用的是dubbo的注解

错误代码

import jdk.nashorn.internal.ir.annotations.Reference;//引用错误,应该引用dubbo的Refence注解
...
@Reference //dubbo的注解,去zookeeper服务注册中心去查找CheckItemService这种接口的服务,封装到对象中
private CheckItemService checkItemService;

正确逻辑

import com.alibaba.dubbo.config.annotation.Reference;//正确引用
...
@Reference //dubbo的注解,去zookeeper服务注册中心去查找CheckItemService这种接口的服务,封装到对象中
private CheckItemService checkItemService;

再次进行发布(maven工程最好clean install一下)测试

2018122814580746.png

2018122814580746.png

测试成功,希望能帮助到问题和我一样的朋友,报错信息有点误导,需要自己经过调试发现问题,总结一下调试思路:

先看网页端的请求是否成功,用开发者工具,看前端控制台报错信息以及网络流,排除前端错误
再根据后台报错信息,通过debug调试定位信息,排除逻辑错误
检查配置文件信息,各种url、path等,尤其看spring是否开启包扫描
通过服务器的命令,排查服务是否进程出错,或者服务并没有注册上,通过工程全关闭,逐个开启观察的方式,定位出问题的模块
是否是同名类包引入错误(此步应该在编写逻辑的时候注意到)


相关实践学习
基于MSE实现微服务的全链路灰度
通过本场景的实验操作,您将了解并实现在线业务的微服务全链路灰度能力。
相关文章
|
6月前
|
应用服务中间件 nginx
【报错】Failed to start A high performance web server and a reverse proxy server.
【报错】Failed to start A high performance web server and a reverse proxy server.
520 2
Web server failed to start. Port XXX was already in use.【完美解决方案】
Web server failed to start. Port XXX was already in use.【完美解决方案】
Web server failed to start. Port XXX was already in use.【完美解决方案】
|
29天前
|
Java Spring
【亲测有效完结bug】org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exce
【亲测有效完结bug】org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exce
77 0
Web server failed to start. Port XXX was already in use.原因分析-解决方案
Web server failed to start. Port XXX was already in use.原因分析-解决方案
472 1
Web server failed to start. Port XXX was already in use.原因分析-解决方案
|
6月前
|
应用服务中间件 Linux
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
144 0
|
6月前
|
Java
org.springframework.web.util.NestedServletException: Request processing failed; nested exception....
org.springframework.web.util.NestedServletException: Request processing failed; nested exception....
145 0
|
存储 缓存 Java
【Java异常】org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet requ
【Java异常】org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet requ
439 0
|
应用服务中间件
Idea解决Web server failed to start. Port 8080 was already in use.端口被占用
Idea解决Web server failed to start. Port 8080 was already in use.端口被占用
776 5
Idea解决Web server failed to start. Port 8080 was already in use.端口被占用
|
Java 应用服务中间件 Spring
运行Spring项目报错 “Web server failed to start. Port 8080 was already in use.”(二)
运行Spring项目报错 “Web server failed to start. Port 8080 was already in use.”(二)
550 0
运行Spring项目报错 “Web server failed to start. Port 8080 was already in use.”(二)
|
Java 应用服务中间件 Spring
运行Spring项目报错“Web server failed to start. Port 8080 was already in use.”(一)
运行Spring项目报错“Web server failed to start. Port 8080 was already in use.”(一)
1341 0
运行Spring项目报错“Web server failed to start. Port 8080 was already in use.”(一)