【发布时间】: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加载的。