为什么spring-boot-3给出javax.servlet.http.HttpServletRequest Clas



当我运行spring-boot-2.7时,没有问题。但是,当我更改代码并将其定制为spring-boot-3.0时,出现了java.lang.ClassNotFoundException:

有人能帮我下载源代码并在你的电脑上运行吗?运行它之后,点击"使用facebook登录",您将看到异常。https://github.com/chuangtc/spring -引导- 3.0 -安全-社会-登录

我尝试添加java servlet api 6.0,但异常仍然存在。

您不必将jakarta servlet api 6.0添加到pom.xml。根据这里的文档,它已经包含了。

在使用javax.servlet.http.HttpServletRequest的代码中,您需要将javax更改为jakarta

所以整行代码是这样的:import jakarta.servlet.http.HttpServletRequest

我以前在升级服务时也遇到过这个错误,我用这种方式解决了它。也许你可以试试。

[编辑]

我看到你的一个依赖是使用javax.servlet:https://mvnrepository.com/artifact/org.springframework.social/spring-social-facebook/2.0.3.RELEASE

在这个github之后,这个包似乎不再被积极维护和归档,所以很可能他们不会为Spring Boot 3升级。

我建议找到其他方法来工作的社交登录的Facebook,也许你可以尝试这种方式?

https://www.codejava.net/frameworks/spring-boot/social-login-with-facebook-example

您也可以尝试添加新的依赖项,如下所示。有了下面的依赖项,我就可以保留javax了。servlet类。

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency> 
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency> 

在我的例子中,我有以下依赖项:

implementation "io.springfox:springfox-swagger2"
implementation "io.springfox:springfox-swagger-ui"

显然依赖于旧的api,因为注释它们解决了这个问题。

相关内容

最新更新