尝试使用 java 17 构建用 java 8 编写的 spring boot 2.7.12 项目时,即使在向 pom 添加依赖项之后,也找不到 Jaxb 类错误

问题描述 投票:0回答:1

当我编译我的 spring 项目时,出现以下错误。

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; Nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
...
Caused by java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
...
Caused by java.lang.ClassNotFoundException: javax.xml.bind.JAXBException

我正在开发一个旧项目,该项目是使用以下软件版本编写的

Java 8 春季启动 2.7.12

我正在尝试使用 java 17 构建这个项目

通过谷歌搜索,我发现8之后的java版本没有jaxb api。因此我将这些依赖项添加到我的 pom.xml 文件中

<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.1</version>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>

<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.2</version>
</dependency>

即使添加它们后,我仍然收到找不到类的错误

java spring spring-boot jaxb java-17
1个回答
0
投票

从 JAXB 3.0 开始,类位于包中

jakarta.xml.bind

javax.xml.bind
适用于 JAXB,直至 2.0。

所以你必须:

  • 将依赖降级为 JAXB 2.0
  • 或者在源文件中使用新路径 jakarta.xml.bind(如果您可以控制依赖类)。
© www.soinside.com 2019 - 2024. All rights reserved.