[英]how to check input type boolean in request body
在请求主体中有一个属性类型为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时出错。
可以帮我解决一下吗
@EnableAutoConfiguration会为WebMvc进行自动配置,因此请排除引发错误的类。
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,WebMvcAutoConfiguration.class })
希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.