【问题标题】:Spring, Maven: Correct the classpath of your applicationSpring,Maven:更正应用程序的类路径
【发布时间】:2020-11-13 14:46:12
【问题描述】:

我正在尝试创建此 course 中使用的基于 gradle 的树屋“unit-testing-a-spring-application”项目的 maven 版本。见课程代码here

在最初无法构建之后,我最终添加了原始 gradle 构建文件中指定的依赖版本。 Maven 会构建得很好,但运行应用程序会给出这样的结果:

The following method did not exist:
    org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)
Ljava/lang/String;

The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is 
available from the following locations:
    jar:file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-
commons/2.1.6.RELEASE/spring-data-commons-2.1.6.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class

It was loaded from the following location:
    file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-commons/2.1.6.RELEASE/spring-
data-commons-2.1.6.RELEASE.jar

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

在 S.O. 上解决了几个类似的问题。通过更改一些相关依赖项的版本。我尝试了以下各种版本但无济于事(我通常坚持使用 spring-boot-starter-parent v2.1.4,因为它一直适用于我的项目):

spring-data-commons
spring-boot-starter-parent

我在我的项目 Dependencies 目录中看到下面列出的所需类,但是在这种情况下哪些依赖版本可以工作?不然怎么解决?

org/springframework/data/repository/config/RepositoryConfigurationSource.class

【问题讨论】:

  • 请检查您的依赖关系。 Imo 接口 RepositoryConfigurationSource 位于版本 X 的依赖项 A 中,该接口的实现位于版本 Y 的依赖项 B 中。并且依赖项 B 中的接口没有此方法。所以可能接口是从依赖项A加载的,但实现是从依赖项B加载的。

标签: java spring maven


【解决方案1】:

我查看了您的代码,发现了一些错误。由于您的项目是 spring-boot 项目,因此您不能在 pom 文件中添加直接的 spring 依赖项。而是尝试使用基于 spring-boot 的依赖项。例如,不要有这样的依赖:

<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.9.2.RELEASE</version>
</dependency>

您的 pom 文件中必须包含以下内容。

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

【讨论】:

  • 我对我的 pom 进行了更改,重新构建,重新运行,但得到了一个不同的缺失类:更正应用程序的类路径,使其包含一个兼容的 org.springframework.orm.jpa 版本.LocalContainerEntityManagerFactoryBea
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-30
  • 2018-03-17
  • 1970-01-01
相关资源
最近更新 更多