gpt4 book ai didi

java.lang.ClassNotFoundException : org. glassfish.jersey.internal.RuntimeDelegateImpl ,抛出 BadRequestException 时

转载 作者:行者123 更新时间:2023-12-02 09:44:10 29 4
gpt4 key购买 nike

我的 springbootapp 中有一个处理程序类,它对传入的 REST 请求执行一些验证,并将 BadRequestException 抛出回 Controller 类。

但是 Controller 不是捕获 BadRequestException,而是捕获 Exception 并抛出

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");
}

这是 Controller

@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);
}

pom.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-rest -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.21</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>


<properties>
<java.version>11</java.version>
</properties>

最佳答案

该类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>

关于java.lang.ClassNotFoundException : org. glassfish.jersey.internal.RuntimeDelegateImpl ,抛出 BadRequestException 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56797072/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com