首页 > 解决方案 > 如何检查请求正文中的输入类型布尔值

问题描述

在请求正文中有一个布尔类型的属性,当我为它传递一个字符串或整数时,它会抛出 httpmessagenotreadableexception。我尝试在我的代码中处理它

 @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 创建错误。

有人可以帮我解决它吗

标签: javaspring-bootexception-handling

解决方案


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

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

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


推荐阅读