我的 springbootapp 中有一個處理程序類,它對傳入的 REST 請求執行一些驗證并將 BadRequestException 拋回控制器類。但不是控制器捕獲 BadRequestException,而是捕獲異常并拋出java.lang.ClassNotFoundException:org.glassfish.jersey.internal.RuntimeDelegateImpl我花了一些時間四處尋找解決方案,但似乎沒有找到任何解決方案。這是我在處理程序中的驗證代碼 private void validateSignUpRequest(String phone) { if(StringUtils.isEmpty(phone)) throw new BadRequestException("Phone Number can't be empty");}這是控制器@PostMapping(path = "/users/sign-up")public ResponseEntity<UserData> signUpUser(@RequestBody Users user) { UserData userData = null; HttpStatus httpStatus = null; boolean flag = false; try { userData = userHandler.fetchByPhone(user.getPhoneNumber()); if (userData == null) { flag = userHandler.saveUser(user); httpStatus = HttpStatus.CREATED; } else { userData = UserData.failureResponse("User Already Exist"); httpStatus = HttpStatus.CONFLICT; } }catch(BadRequestException e) { userData = UserData.failureResponse(e.getMessage()); httpStatus = HttpStatus.BAD_REQUEST; } catch (Exception e) { userData = UserData.failureResponse(e.getMessage()); httpStatus = HttpStatus.INTERNAL_SERVER_ERROR; } return new ResponseEntity<>(userData,httpStatus);}
1 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
此類https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/internal/RuntimeDelegateImpl.java在 jersey-common 下。
你缺少jersey-common
?https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common
????<dependency> ???????<groupId>org.glassfish.jersey.core</groupId> ???????<artifactId>jersey-common</artifactId> ???????<version>.....</version> ????</dependency>
添加回答
舉報
0/150
提交
取消