【问题标题】:Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.jpa.repository.config更正应用程序的类路径,使其包含一个兼容的 org.springframework.data.jpa.repository.config 版本
【发布时间】:2020-01-23 17:46:33
【问题描述】:

我无法理解错误,我该怎么办? 更正应用程序的类路径,使其包含一个兼容的 org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension 版本

Description:

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

    org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerBeansForRoot(JpaRepositoryConfigExtension.java:169)

The following method did not exist:

    org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerIfNotAlreadyRegistered(Lorg/springframework/beans/factory/support/AbstractBeanDefinition;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;Ljava/lang/String;Ljava/lang/Object;)V

The method's class, org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension, is available from the following locations:

    jar:file:/C:/Users/HCL/.m2/repository/org/springframework/data/spring-data-jpa/2.0.2.RELEASE/spring-data-jpa-2.0.2.RELEASE.jar!/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtension.class

It was loaded from the following location:

    file:/C:/Users/HCL/.m2/repository/org/springframework/data/spring-data-jpa/2.0.2.RELEASE/spring-data-jpa-2.0.2.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension

我添加了最新版本的依赖项,尽管它会再次显示

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
        <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>2.0.2.RELEASE</version>
</dependency>

        <dependency>
    <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>


        <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>javax.persistence-api</artifactId>
    <version>2.2</version>
</dependency>
        <!-- https://mvnrepository.com/artifact/javax.transaction/jta -->

        <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.3.15.2</version>
</dependency>
    </dependencies>

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

</project>

请帮忙!

【问题讨论】:

  • 我猜你正在使用不同版本的一些 spring-boot 依赖项。如果您需要更详细的帮助,您可能应该发布您的 pom.xml
  • 请检查,我发布了我的 pom.xml

标签: spring-boot


【解决方案1】:

您不应提及spring-data-jpa 的版本。 Spring-boot 父依赖会自动解决。

而不是这个:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <! -- <version>2.0.2.RELEASE</version>  comment or remove this line -->
</dependency>

更新: 您使用的是spring-boot-starter-parent 版本2.2.4 和不同的spring-data-jpa 版本,这就是报错的原因。

【讨论】:

    【解决方案2】:

    你应该使用 spring-data-jpa 和 spring-boot-starter-jdbc:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    

    【讨论】:

      【解决方案3】:

      您应该参考 STS 执行以下步骤:

      1. 在 build.graddle 中调整正确的依赖关系
      2. 擦除缓存目录(通常在'C:\Users\your-name\.gradle\caches')
      3. 清理项目(主菜单>项目>清理...)
      4. 在主java中右击Run as > Spring Boot App 或
      5. 在 Project Explorer 中右键单击项目名称 > Gradle > 刷新 Gradle 项目

      然后错误就会消失!

      【讨论】:

        【解决方案4】:

        请使用给定的依赖项:

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.6.4</version> <!- use latest version -->
            <relativePath /> <!-- lookup parent from repository -->
        </parent>
        
        <dependencies>
            <dependency>
               <groupId>org.springframework.boot</groupId>
               <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
        </dependencies>
        

        问题的发生是因为 pom.xml 中可用的依赖项版本不兼容,导致同一类的版本冲突。所以,从你的 pom 中删除显式版本声明,让 maven 从父 pom 的托管版本中解析依赖关系。

        【讨论】:

          猜你喜欢
          • 2022-01-01
          • 2021-06-29
          • 2019-08-11
          • 2021-07-08
          • 2021-11-07
          • 2021-04-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多