英文:
Spring, Maven: Correct the classpath of your application
问题
我正在尝试创建一个基于Maven的Gradle项目树“unit-testing-a-spring-application”的版本,该项目在这个课程中使用。请参阅课程代码此处。
起初我无法构建,最终不得不添加原始Gradle构建文件中指定的依赖版本。Maven构建可以正常进行,但运行应用程序会出现以下错误:
以下方法不存在:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)
Ljava/lang/String;
方法的类org.springframework.data.repository.config.RepositoryConfigurationSource位于以下位置:
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
它是从以下位置加载的:
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。
在这里,通过更改某些相关依赖的版本来解决了类似的问题。我尝试了以下几个版本,但都没有成功(通常我会坚持使用spring-boot-starter-parent v2.1.4,因为它在我的项目中一直有效):
spring-data-commons
spring-boot-starter-parent
我在项目的依赖目录中看到下面所需的类,但是在这种情况下,哪个依赖版本能够正常工作呢?另外,我如何解决这个问题?
org/springframework/data/repository/config/RepositoryConfigurationSource.class
英文:
I am trying to create a maven version of the gradle-based treehouse 'unit-testing-a-spring-application' project used in this course. See course code here.
After not being able to build initially, I ended up adding dependency versions specified in the original gradle build file. Maven will build fine, but running the app gives this:
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.
Several similar problems are solved here on S.O. by changing the version of some related dependency. I have tried various versions of the following to no avail (I stick normally with spring-boot-starter-parent v2.1.4 cause it works all the time with my projects):
spring-data-commons
spring-boot-starter-parent
I see the needed class below listed in my project Dependencies directory, but what dependency versions will work in this case? How can I solve this otherwise?
org/springframework/data/repository/config/RepositoryConfigurationSource.class
答案1
得分: 0
我查看了你的代码并发现了一些错误。由于你的项目是一个 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>
英文:
I looked at your code and found some mistakes. Since your project is a spring-boot one, you mustn't add direct spring dependencies in your pom file. Instead try to use spring-boot based dependencies. For instance, instead of having such this dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
You must have the following one in your pom file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
专注分享java语言的经验与见解,让所有开发者获益!
评论