如何检查请求正文中的输入类型布尔值

时间:2019-02-26 03:02:50

标签: java spring-boot exception-handling

在请求正文中的

有一个属性类型为boolean的属性,当我为其传递字符串或整数时,它会抛出httpmessagenot可读异常。我尝试在我的代码中处理它

 @SuppressWarnings("unchecked")
  @ExceptionHandler(HttpMessageNotReadableException.class)
  public final ResponseEntity<Object> handleAllExceptions(HttpMessageNotReadableException ex, WebRequest request) {

    return new ResponseEntity(HttpStatus.BAD_REQUEST);
  }

但它显示一条消息:

在类路径资源[org / springframework / boot / autoconfigure / web / servlet / WebMvcAutoConfiguration $ EnableWebMvcConfiguration.class]中创建名称为'handlerExceptionResolver'的bean时出错。

有人可以帮我解决问题吗

2 个答案:

答案 0 :(得分:0)

您可以添加spring控制台错误以获取更多详细信息。
您的return语句应包含Object,如下所示。 Refer this for Exception Handling

4.000000039384161
4.000000039384161
4.99999996369956
4.99999996369956
5.999999857891461
5.999999857891461
6.999999889918595
6.999999889918595
7.99999992894573
7.99999992894573
8.999999928945726
8.999999928945726

答案 1 :(得分:0)

@EnableAutoConfiguration会为WebMvc进行自动配置,因此请排除引发错误的类。

   @EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,WebMvcAutoConfiguration.class })

我希望这可以解决您的问题。

相关问题