java.lang.ClassNotFoundException: org.glassfish

我的 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);

}


MM们
浏览 464回答 1
1回答

四季花海

此类https://github.com/jersey/jersey/blob/master/core-common/src/main/java/org/glassfish/jersey/internal/RuntimeDelegateImpl.java在 jersey-common 下。你缺少jersey-common&nbsp;https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common&nbsp;&nbsp;&nbsp;&nbsp;<dependency> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<groupId>org.glassfish.jersey.core</groupId> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<artifactId>jersey-common</artifactId> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<version>.....</version> &nbsp;&nbsp;&nbsp;&nbsp;</dependency>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java