gpt4 book ai didi

maven - 启动 spring boot "An attempt was made to call a method that does not exist"时出错

转载 作者:行者123 更新时间:2023-12-03 13:57:22 25 4
gpt4 key购买 nike

当我运行 spring boot 应用程序时,intellij 返回一个错误:

An attempt was made to call a method that does not exist. The attempt was made from the following location:


org.hibernate.envers.boot.internal.TypeContributorImpl.contribute(TypeContributorImpl.java:30)

以下方法不存在:
org.hibernate.boot.model.TypeContributions.contributeJavaTypeDescriptor(Lorg/hibernate/type/descriptor/java/spi/JavaTypeDescriptor;)V

该方法的类 org.hibernate.boot.model.TypeContributions 可从以下位置获得:
jar:file:/C:/Users/romul/.m2/repository/org/hibernate/hibernate-core/5.4.6.Final/hibernate-core-5.4.6.Final.jar!/org/hibernate/boot/model/TypeContributions.class
jar:file:/C:/Users/romul/.m2/repository/org/hibernate/orm/hibernate-core/6.0.0.Alpha2/hibernate-core-6.0.0.Alpha2.jar!/org/hibernate/boot/model/TypeContributions.class

它是从以下位置加载的:
file:/C:/Users/romul/.m2/repository/org/hibernate/hibernate-core/5.4.6.Final/hibernate-core-5.4.6.Final.jar

行动:

更正应用程序的类路径,使其包含一个兼容的 org.hibernate.boot.model.TypeContributions 版本

这可能是我的 pom.xml 冲突?

这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.produtos</groupId>
<artifactId>api-rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>api-rest</name>
<description>Demo project for Spring Boot</description>

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>12</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.26.0-GA</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.0.0.Alpha2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.8.Final</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

我该如何解决?

最佳答案

您不应将 Hibernate 的版本指定为 spring-boot-starter-data-jpa依赖负责解决这个问题。

如果您运行 mvn dependency:tree | grep hibernate ,您会看到包含 2 个版本的 hibernate:

16:20 $ mvn dependency:tree | grep hibernate
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.0.17.Final:compile
[INFO] | +- org.hibernate:hibernate-core:jar:5.4.6.Final:compile
[INFO] +- org.hibernate.orm:hibernate-core:jar:6.0.0.Alpha2:compile
[INFO] | +- org.hibernate.common:hibernate-commons-annotations:jar:5.1.0.Final:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.4.8.Final:compile

似乎组 id 从 org.hibernate 改变了至 org.hibernate.orm ,这就是 Maven 没有注意到它是同一个库的原因。

还有 hibernate-entitymanager可以删除依赖项。

关于maven - 启动 spring boot "An attempt was made to call a method that does not exist"时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58671257/

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