https://jira.spring.io/browse/SPR-12888

Description

When I use @RequestBody on one of my controllers for a required parameter, I need some useful way of saying which parameter was missing if it's not there. The exception message I see currently looks like this:

Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@a8b8886e
	at org.springframework.test.util.MatcherAssertionErrors.assertThat(MatcherAssertionErrors.java:80)
	at org.springframework.test.util.JsonPathExpectationsHelper.assertValue(JsonPathExpectationsHelper.java:92)
	at org.springframework.test.web.servlet.result.JsonPathResultMatchers$1.match(JsonPathResultMatchers.java:56)
	at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
...

It would be nice if when that exception could have a reference to the parameter name that was missing, or if the message itself included it instead of the MethodParameter#toString(). I'll eventually want to internationalize the message I produce, so the parameter name is preferable.

Activity

 
Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM

The HttpMessageNotReadableException can be raised from many places where a method parameter does not apply so adding a new field to the exception isn't ideal. I considered sub-classing the exception but what I've done instead is to print the full method signature to improve the error message. Also we now support injecting the selected HandlerMethod into an @ExceptionHandler method so you can obtain the full information on the @RequestMapping method we were trying to call.

Rossen Stoyanchev added a comment - 06/Apr/15 2:57 PM

Resolving for now but feel free to comment further.

Better exception message for missing @RequestBody method parameter的更多相关文章

  1. CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法

    CAS (10) -- JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法 jboss版本: jb ...

  2. Use Exception.ToString() instead of Exception.Message.

    Exception.Message contains only the message (doh) associated with the exception. Example: Object ref ...

  3. java.lang.Exception: No tests found matching Method tes(com.bw.test.Testrefiect) from org.junit.vintage.engine.descriptor.RunnerRequest@3bfdc050 at org.junit.internal.requests.FilterRequest.getRunner

    junit   方法  没有加上注解  @Test java.lang.Exception: No tests found matching Method tes(com.bw.test.Testre ...

  4. jenkins编辑报错Exception when publishing, exception message的解决办法

    jenkins编辑报错Exception when publishing, exception message的解决办法 查看目标主机的磁盘空间是否占满,清理磁盘空间即可

  5. Exception message: /bin/bash: line 0: fg: no job control

    这个错误是 我本地idea 远程调试hadoop集群出现的 Diagnostics: Exception from container-launch. Container id: container_ ...

  6. 记一次Jenkins 打包异常 ERROR: Exception when publishing, exception message [Failure]

    今天早上打包一直都没有问题,突然有一次打包突然出现异常现象,如下: ERROR: Exception when publishing, exception message [Failure] Buil ...

  7. 错误:java.lang.Exception: No tests found matching Method testPrePage1(egou_manager_web.TestEBrand) from org.junit.internal.requests.ClassRequest@4f3cc73c

    今天测试分页时出现以下错误: java.lang.Exception: No tests found matching Method testPrePage1(egou_manager_web.Tes ...

  8. How to receive JSON as an MVC 5 action method parameter

    How to receive JSON as an MVC 5 action method parameter  解答1 Unfortunately, Dictionary has problems ...

  9. Yarn报错:Exception message: /bin/bash: line 0: fg: no job control

    Exception message: /bin/bash: line 0: fg: no job control 这个错误是 本地idea跨平台远程调试hadoop集群出现的,在使用windows调用 ...

随机推荐

  1. js模仿微信语音播放的小功能

    自己写的一个模仿微信语音播放的小功能,实现的主要功能是:点击播放,点击暂停,播放切换,,,  代码如下: <!DOCTYPE html> <html lang="en&qu ...

  2. 解决Yii2 添加css后页面刷新也无反应的情况

    'assetManager' => [ // uncomment the following line if you want to auto update your assets (unix ...

  3. centos7基本环境搭建

    1. 准备权限:让普通用户具备sudo执行权限 切换到root用户,su # vi /etc/sudoers 添加  koushengrui    ALL=(ALL)       ALL 这里很容易忘 ...

  4. shell查看内存

    <1>jps<2>ps<3>free<4>df<5>top jps: 很多Java命令都在jdk的JAVA_HOME/bin/目录下面,jp ...

  5. Kudu的Using Apache Kudu with Apache Impala(官网推荐的步骤)

    不多说,直接上干货! http://kudu.apache.org/docs/kudu_impala_integration.html http://blog.csdn.net/lovebyz/art ...

  6. 04-spring中的aop演示

    1 xml配置 1 导包 2 准备对象 package www.test.service; public interface UserService { public abstract void ad ...

  7. 数据结构之C语言模拟整数数组实现

    #include <stdio.h> #include <malloc.h> #include <stdlib.h> typedef struct Arr { in ...

  8. WCF:无法满足对安全令牌的请求,因为身份验证失败。

    服务端和客户端如果有认证的话的这样: <wsHttpBinding> <binding name="WSHttpBinding_IService1" closeT ...

  9. sqlmap 命令笔记

    基础命令 注入 MySQL mssql access 直接爆表.然后你懂的BT5里面的话前面就要加pythonsqlmap.py -u url --dbs //爆数据库sqlmap.py -u url ...

  10. Django auth组件拓展 关联外部信息---------------------------- Profile 模式

    https://docs.djangoproject.com/en/2.1/topics/auth/customizing/ 官方文档. 网上的get_profile 方法不好用太假了 可能我没用明白 ...