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. sf01_什么是数据结构

    数据结构解决什么问题 如何在计算机中存储数据和信息,采用什么样的方法和技巧加工处理这些数据,都是数据结构需要努力解决的问题. 解决问题的步骤 使用计算机解决问题的步骤:分析具体问题得到数学模型,设计解 ...

  2. java——抽象类、接口、二者区别

    抽象类: 抽象方法:不包含方法体的方法为抽象方法,抽象方法必须使用abstract关键字来修饰: abstract void method(); 抽象类:当一个类中包含了抽象方法时,该类必须使用abs ...

  3. Android Studio CMake 生成多个so

    生成多个so案例 这里stringFromJNI和stringFromJNI11分别是调用one-lib和two-lib两个so package com.test.ndkmoreso; import ...

  4. 性能测试工具LoadRunner29-LR之测试java代码

    步骤: 1.安装配置JDK(注意LR11最高支持jdk1.6的版本) 2.JAR包的导入 在LR中创建java Vuser脚本并且保存,我保存的文件夹名称为lr_java 将jar包放到这个文件夹下 ...

  5. 第8章 IO类

    8.1 IO类 iostream                    istream, wistream从流中读取数据 ostream, wostream iostream, wiostream读写 ...

  6. Spring Boot2中Spring Security导致Eureka注册失败

    将Spring Boot升级到2.0,Spring Cloud升级到Finchley.M8时,Eureka注册就报错了 Eureka Server配置: server.port=9011 spring ...

  7. Java学习笔记--继承和多态(中)

    1.通过继承来开发超类(superclass) 2.使用super 关键词唤起超类的构造方法 3.在超类中覆盖方法 4.区分override和overload 5.在Object类中探索toStrin ...

  8. 利用COM组件实现对WORD书签处写入值

    using System; using System.Collections.Generic; using System.Text; using Microsoft.Office.Interop.Wo ...

  9. 2.C#中的常用快捷键

    快速对齐代码: Ctrl+K+D:  快速对齐代码   (如果代码语法错误,就不能使用) Ctrl+Z:  撤销 Ctrl+S:保存   没事就Ctrl+S一下,防止因为电脑断电,代码全部丢失 Ctr ...

  10. JDBC之Java连接mysql实现增删改查

    使用软件:mysql.eclipse 链接步骤: 1.注册驱动 2.创建一个连接对象 3.写sql语句 4.执行sql语句并返回一个结果或者结果集 5.关闭链接(一般就是connection.stat ...