Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Spring引导中,TypeMismatchException.getPropertyName()始终返回null_Spring_Spring Boot_Type Mismatch_Exceptionhandler - Fatal编程技术网

在Spring引导中,TypeMismatchException.getPropertyName()始终返回null

在Spring引导中,TypeMismatchException.getPropertyName()始终返回null,spring,spring-boot,type-mismatch,exceptionhandler,Spring,Spring Boot,Type Mismatch,Exceptionhandler,在我的Spring引导应用程序中,我有一个带有RequestParam Integer clockDrift的控制器方法。当从Postman测试它时,如果我提供整数值,一切都按预期工作。但如果我在clockDrift字段中提供任何字符串值,则请求将发送到handler类中的HandletTypeMismatch方法。我试图从TypeMismatchException ex获取属性名。我总是得到null。通过Eclipse,如果我检查ex,我能够在名称下看到“时钟漂移”(我看到F符号靠近它。不确定

在我的Spring引导应用程序中,我有一个带有RequestParam Integer clockDrift的控制器方法。当从Postman测试它时,如果我提供整数值,一切都按预期工作。但如果我在clockDrift字段中提供任何字符串值,则请求将发送到handler类中的HandletTypeMismatch方法。我试图从TypeMismatchException ex获取属性名。我总是得到null。通过Eclipse,如果我检查ex,我能够在名称下看到“时钟漂移”(我看到F符号靠近它。不确定那是什么。如果你能解释F的意义,我将不胜感激)。但不确定如何获取name的值。除了getPropertyName()之外,我看不到任何方法。如何从TypeMismatchException对象获取属性名

@Order(Ordered.HIGHEST_PRECEDENCE)
@RestControllerAdvice
public class ApiGlobalExceptionHandler extends ResponseEntityExceptionHandler
{
..
..
  @Override
  protected ResponseEntity<Object> handleTypeMismatch(TypeMismatchException ex, HttpHeaders headers, HttpStatus status,
      WebRequest request)
  {
    System.out.println(ex.getPropertyName()); -- Returning null
    String message = "Input value '" + ex.getValue() + "'" + " is  invalid. Required type is "
        + ex.getRequiredType().getSimpleName();

    return ResponseEntity.status(status).body(SecurityTransformationUtil.buildServiceMessageResponse(status, message));
  } 
@顺序(有序。最高优先级)
@再控制建议
公共类ApiGlobalExceptionHandler扩展了ResponseEntityExceptionHandler
{
..
..
@凌驾
受保护的响应HandletTypeMitch(TypeMitchException ex、HttpHeaders标头、HttpStatus状态、,
WebRequest(请求)
{
System.out.println(例如getPropertyName());--返回null
字符串消息=“输入值””+ex.getValue()+“+”无效。所需类型为“
+例如:getRequiredType().getSimpleName();
返回ResponseEntity.status(status).body(SecurityTransformationUtil.buildServiceMessageResponse(status,message));
} 

您好,我想知道如果从未调用过initPropertyName,是否可以通过根据javadoc调用来获取名称。如果没有填充initPropertyName,则属性名称不被填充。很可能创建此异常的任何对象都不会这样做。@IronMan ex.getPropertyChangeEvent().getPropertyName();计算失败。原因:java.lang.NullPointerException位于getPropertyName()处