java - 如何检查请求正文中的输入类型布尔值
问题描述
在请求正文中有一个布尔类型的属性,当我为它传递一个字符串或整数时,它会抛出 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 创建错误。
有人可以帮我解决它吗
解决方案
@EnableAutoConfiguration 对 WebMvc 进行自动配置,因此请排除引发错误的类。
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,WebMvcAutoConfiguration.class })
我希望这可以解决您的问题。
推荐阅读
- python-3.x - 如何使用 kv 语言在 Kivy 中循环?
- node.js - 使用带有 Jest 的 ws 模块模拟和测试 websocket
- .htaccess - htaccess url 错误用另一个 url 重写
- python - 根据pyspark中第一行的值填充后续的空值
- c# - 从代码隐藏设置 HTML5 可拖动属性不起作用?
- react-native - react-native-maps 使用哪个 api 以及它的成本如何?
- javascript - 用控制台中的 jquery 字符串替换 youtube 上的 favicon
- laravel - 在 cPanel 上设置 Laravel 项目
- python-3.x - Youtube Api 更新 publishAt TypeError python
- spring-boot - 无法使用邮递员请求调试 Spring Boot 应用程序