简体   繁体   中英

how to check input type boolean in request body

in request body have an attribute has type boolean, when i pass a string or an integer for it, it throw httpmessagenotreadableexception. I try to handle it in my code

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

    return new ResponseEntity(HttpStatus.BAD_REQUEST);
  }

but it show a message:

Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class].

Can some one help me how to fix it

@EnableAutoConfiguration does auto configs for WebMvc, so please exclude the class due to which the error is throwing up.

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

I hope this resolves your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM