如何解决Spring Boot拒绝启动,AbstractRepositoryConfigurationSourceSupport问题
我使用Spring Starter创建了一个项目,但无法运行。它给我一个错误消息,看起来像这样:
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$AutoConfiguredAnnotationRepositoryConfigurationSource.<init>(AbstractRepositoryConfigurationSourceSupport.java:133)
The following method did not exist:
org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDeFinitionRegistry;Lorg/springframework/beans/factory/support/BeanNameGenerator;)V
The method's class,org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource,is available from the following locations:
jar:file:/Users/miguelmunoz/.m2/repository/org/springframework/data/spring-data-commons/1.13.10.RELEASE/spring-data-commons-1.13.10.RELEASE.jar!/org/springframework/data/repository/config/AnnotationRepositoryConfigurationSource.class
The class hierarchy was loaded from the following locations:
org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource: file:/Users/miguelmunoz/.m2/repository/org/springframework/data/spring-data-commons/1.13.10.RELEASE/spring-data-commons-1.13.10.RELEASE.jar
org.springframework.data.repository.config.RepositoryConfigurationSourceSupport: file:/Users/miguelmunoz/.m2/repository/org/springframework/data/spring-data-commons/1.13.10.RELEASE/spring-data-commons-1.13.10.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single,compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource
我不知道该如何解决。我已经在https://github.com/SwingGuy1024/dummy.artifact-MRTC
处签入了一个最小的可重复测试用例我的pom文件如下:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dummy</groupId>
<artifactId>dummy.artifact</artifactId>
<packaging>jar</packaging>
<name>dummy.artifact</name>
<version>1.0</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.9.2</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<!--<version>2.3.3.RELEASE</version>--> <!--I tried both. Neither version worked.-->
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<!--Handles serialization/deserialization of new Java Date/Time classes-->
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Neumann-SR4</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
</project>
附录:据我所知,我只有一个版本的AnnotationRepositoryConfigurationSource,它位于spring-data-commons存储库中。据我了解,spring-data的版本应由pom.xml文件的dependencyManagement部分确定,在其中我指定了spring-data-releasetrain。为此,我尝试了几种不同的值,但没有一种起作用。这里指定的一个Neumann-SR4
是最新的一个。但这并没有为我提供spring-data-commons的最新版本。
附录2: 下面由gtiwari333建议的更改
我进行了以下更改并将其检入GitHub存储库。而且我仍然有问题。
- 我将类RFC3339DateFormat和Swagger2SpringBoot移至虚拟包,并将参数调整为@ComponentScan注释。
- 我将CTwo重命名为CTwoDto,并在新的
dummy.entity
包中创建了一个新的CTwo类。 - 存储库现在使用新的CTwo实体类
- 我将Spring-Boot版本提高到了2.3.3.RELEASE。 (2.3.4给我一个昂首阔步的文件中的编译器错误-它找不到
javax.servlet.http.HttpServletRequest
) - 我删除了三个依赖项:
jackson-datatype-jsr310
,validation-api
和jackson-annotations
- 我从pom文件中删除了dependencyManagement部分。
- 我摆弄着日志级别。
(这些更改将我带到了导致我创建此MRTC的原始错误。)
我仍然收到错误消息,尽管有所不同。
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(AnnotationRepositoryConfigurationSource.java:126)
The following method did not exist:
org.springframework.core.type.AnnotationMetadata.introspect(Ljava/lang/Class;)Lorg/springframework/core/type/AnnotationMetadata;
The method's class,org.springframework.core.type.AnnotationMetadata,is available from the following locations:
jar:file:/Users/miguelmunoz/.m2/repository/org/springframework/spring-core/5.1.9.RELEASE/spring-core-5.1.9.RELEASE.jar!/org/springframework/core/type/AnnotationMetadata.class
It was loaded from the following location:
file:/Users/miguelmunoz/.m2/repository/org/springframework/spring-core/5.1.9.RELEASE/spring-core-5.1.9.RELEASE.jar
Action:
Correct the classpath of your application so that it contains a single,compatible version of org.springframework.core.type.AnnotationMetadata
再一次,我只有一个单独的类的问题。
解决方法
我看到您的代码有几个问题。这些中的一项或全部可能会导致您面临的问题。
- 您在根软件包
dummy.invoker.Swagger2SpringBoot
上没有dummy
。 Spring Boot建议您将@SpringBootApplication类放在根包中,以便它扫描所有组件和存储库,而无需您手动扫描。 如果必须将此类放在dummy.invoker
包中,请执行以下操作以扫描Repository类@EnableJpaRepositories(basePackages = {"dummy.repository"})
还
@EntityScan(basePackages = {"dummy.model"})
扫描CTwo实体
- CTwo不是正确的Entity类。但是您正在CTwoRepository上使用它。使它成为具有@Id 的Entity类
@Entity
public class CTwo {
@JsonProperty("id")
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id = null;
其他注意事项:
- 无需覆盖springframework.data版本。从pom.xml中删除它。 Spring
spring-boot-starter-data-jpa
提取与给定的Spring Boot版本一起使用的正确版本。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Neumann-SR4</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
- 无需将@Repository和@Component放在存储库类中
@Repository
@Component
public interface CTwoRepository ...
- 无需覆盖
jackson-annotations
版本。实际上,您根本不需要放置此依赖项。另外,无需定义jackson-datatype-jsr310,validation-api。它们是在传递时被拉动的。
有关运行应用程序之前需要进行的更改,请参见此修补程序:
此外,为什么还要使用旧的Spring Boot版本?请更新为最新。
Index: src/main/java/dummy/repository/CTwoRepository.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/dummy/repository/CTwoRepository.java (revision 27a2e1045263f79fd3c490fce14b2640b12fa3a4)
+++ src/main/java/dummy/repository/CTwoRepository.java (date 1601681768001)
@@ -12,7 +12,5 @@
*
* @author Miguel Mu\u00f1oz
*/
-@Repository
-@Component
public interface CTwoRepository extends JpaRepository<CTwo,Integer> {
}
Index: src/main/java/dummy/model/CTwo.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/dummy/model/CTwo.java (revision 27a2e1045263f79fd3c490fce14b2640b12fa3a4)
+++ src/main/java/dummy/model/CTwo.java (date 1601681492814)
@@ -7,18 +7,22 @@
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
+
+import javax.persistence.*;
import javax.validation.Valid;
import javax.validation.constraints.*;
/**
* CTwo
*/
-@Validated
-@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen",date = "2020-10-01T10:23:27.051Z[GMT]")
+//@Validated
+//@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen",date = "2020-10-01T10:23:27.051Z[GMT]")
@JsonInclude(JsonInclude.Include.NON_NULL)
-
+@Entity
public class CTwo {
@JsonProperty("id")
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id = null;
@JsonProperty("name")
Index: pom.xml
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- pom.xml (revision 27a2e1045263f79fd3c490fce14b2640b12fa3a4)
+++ pom.xml (date 1601682065794)
@@ -15,8 +15,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
- <version>2.1.7.RELEASE</version>
- <!--<version>2.3.3.RELEASE</version>--> <!--I tried both. Neither version worked.-->
+ <version>2.3.4.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
@@ -74,55 +73,5 @@
<version>${springfox-version}</version>
</dependency>
- <!--<dependency>-->
- <!-- <groupId>jakarta.xml.bind</groupId>-->
- <!-- <artifactId>jakarta.xml.bind-api</artifactId>-->
- <!-- <version>2.3.2</version>-->
- <!--</dependency>-->
-
- <!--<!– Runtime,com.sun.xml.bind module –>-->
- <!--<dependency>-->
- <!-- <groupId>org.glassfish.jaxb</groupId>-->
- <!-- <artifactId>jaxb-runtime</artifactId>-->
- <!-- <version>2.3.2</version>-->
- <!--</dependency>-->
-
- <dependency>
- <!--Handles serialization/deserialization of new Java Date/Time classes-->
- <groupId>com.fasterxml.jackson.datatype</groupId>
- <artifactId>jackson-datatype-jsr310</artifactId>
- </dependency>
- <!-- Bean Validation API support -->
- <dependency>
- <groupId>javax.validation</groupId>
- <artifactId>validation-api</artifactId>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>2.10.1</version>
- </dependency>
-
- <!--<!–Actuator–>-->
- <!--<dependency>-->
- <!-- <groupId>org.springframework.boot</groupId>-->
- <!-- <artifactId>spring-boot-actuator-docs</artifactId>-->
- <!-- <version>1.5.10.RELEASE</version>-->
- <!--</dependency>-->
- <!--<dependency>-->
- <!-- <groupId>org.springframework.boot</groupId>-->
- <!-- <artifactId>spring-boot-starter-actuator</artifactId>-->
- <!--</dependency>-->
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-releasetrain</artifactId>
- <version>Neumann-SR4</version>
- <scope>import</scope>
- <type>pom</type>
- </dependency>
- </dependencies>
- </dependencyManagement>
</project>
Index: src/main/java/dummy/invoker/Swagger2SpringBoot.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/dummy/invoker/Swagger2SpringBoot.java (revision 27a2e1045263f79fd3c490fce14b2640b12fa3a4)
+++ src/main/java/dummy/invoker/Swagger2SpringBoot.java (date 1601681394614)
@@ -4,13 +4,17 @@
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableSwagger2
-@ComponentScan(basePackages = { "dummy.invoker","dummy.api","dummy.config","dummy.repository"})
+@EnableJpaRepositories(basePackages = {"dummy.repository"})
+@EntityScan(basePackages = {"dummy.model"})
+@ComponentScan(basePackages = { "dummy.invoker","dummy.config" })
public class Swagger2SpringBoot implements CommandLineRunner {
@Override
,
好像您在spring lib之间有冲突-此处描述了几乎相同的问题:
how to make spring data lib compatiable in spring boot 2.x?
提示:尝试调试此类错误时,请先搜索您所获得的似乎相关的确切错误消息的一部分(将其粘贴)。如果没有立即发现问题,请尝试将其范围缩小到通用,然后您会发现类似的问题。
还值得注意的是,在输出末尾有一条消息,描述了解决该问题所需采取的措施:
Action:
Correct the classpath of your application so that it contains a single,compatible version of org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource
这表明“某些类”有两个以上的兼容版本。如果您专门搜索提到的有问题的课程,则可能会发现更多人遇到完全相同的问题及其解决方案。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。