第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

@ExceptionHandler 不捕獲 MethodArgumentNotValid

@ExceptionHandler 不捕獲 MethodArgumentNotValid

慕村225694 2021-10-17 16:01:33
我有以下幾點@ControllerAdvice:@ControllerAdvicepublic class ExceptionHandlingController {    @ExceptionHandler(value = { MethodArgumentNotValidException.class,            EntityExistsException.class, BadCredentialsException.class, MismatchedInputException.class })    public ResponseEntity<ExceptionResponse> invalidInput(RuntimeException ex) {        ExceptionResponse response = new ExceptionResponse();        response.setErrorCode("BAD_REQUEST");        response.setErrorMessage(ex.getMessage());        return new ResponseEntity<ExceptionResponse>(response,                HttpStatus.BAD_REQUEST);    }}驗證器以這種方式綁定到控制器:@RestController@RequestMapping("/api/authentication")public class UserAccountControllerImpl implements UserAccountController {    @Autowired    private UserAccountService userAccountService;    @Override    public UserAccountEntity login(@Valid @RequestBody UserAccountEntity account,            HttpServletResponse response) throws BadCredentialsException {        return userAccountService.authenticateUserAndSetResponsenHeader(                account.getUsername(), account.getPassword(), response);    }    @Override    public UserAccountEntity create(@Valid @RequestBody UserAccountEntity userAccount,            HttpServletResponse response) throws EntityExistsException {        String username = userAccount.getUsername();        String password = userAccount.getPassword();        userAccountService.saveIfNotExists(username, password);        return userAccountService.authenticateUserAndSetResponsenHeader(                username, password, response);    }    //used to bind the validator to the incoming request    @InitBinder    public void binder(WebDataBinder binder) {        binder.addValidators(new UserAccountValidator());    }}為什么抓不到MethodArgumentNotValidException?
查看完整描述

1 回答

?
至尊寶的傳說

TA貢獻1789條經(jīng)驗 獲得超10個贊

至少,異常 MethodArgumentNotValidException 不是 RuntimeException,但您在該異常處理程序中使用 RuntimeException 參數(shù)。對于測試,將方法參數(shù)中的 RuntimeException 更改為 Exception。


查看完整回答
反對 回復(fù) 2021-10-17
  • 1 回答
  • 0 關(guān)注
  • 984 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號