You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot集成DynamoDB复合主键时遇ReflectionEntityInformation缺失问题求助

问题排查与解决方案

核心原因

org.springframework.data.repository.core.support.ReflectionEntityInformation 是Spring Data Commons包里的类,启动报错找不到它,本质就是依赖未引入或者Spring Data各模块版本不兼容导致的。

解决步骤

1. 补全Spring Data Commons依赖

如果用Maven,把这段代码加到pom.xml中(版本无需手动指定,Spring Boot父工程会自动匹配对应版本):

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
</dependency>

如果是Gradle项目,添加到build.gradle:

implementation 'org.springframework.data:spring-data-commons'

2. 对齐Spring Data版本

Spring Boot和Spring Data DynamoDB的版本必须严格适配,乱指定版本必然出问题:

  • Spring Boot 2.x 对应 Spring Data DynamoDB 5.x
  • Spring Boot 3.x 对应 Spring Data DynamoDB 6.x

比如Maven中手动指定版本时要匹配:

<dependency>
    <groupId>com.github.derjust</groupId>
    <artifactId>spring-data-dynamodb</artifactId>
    <version>5.2.0</version> <!-- 适配Spring Boot 2.7.x版本 -->
</dependency>

3. 清理依赖缓存并重新构建

本地依赖缓存损坏也可能导致类找不到,执行以下命令清理并重新构建:

  • Maven:mvn clean install -U
  • Gradle:./gradlew clean build --refresh-dependencies

4. 检查配置类正确性

确保DynamoDB配置类没有引入其他数据模块的过时API,避免混淆,保持配置仅针对DynamoDB:

@Configuration
@EnableDynamoDBRepositories(basePackages = "com.yourpackage.repository")
public class DynamoDBConfig {

    @Value("${aws.dynamodb.endpoint}")
    private String endpoint;

    @Bean
    public AmazonDynamoDB amazonDynamoDB() {
        return AmazonDynamoDBClientBuilder.standard()
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, "us-east-1"))
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummy", "dummy")))
                .build();
    }
}

验证方法

  1. 重启项目,查看该类找不到的报错是否消失
  2. 若仍有问题,执行mvn dependency:tree(Maven)或./gradlew dependencies(Gradle),检查spring-data-commons是否被正确引入,以及是否存在版本冲突

内容的提问来源于stack exchange,提问作者Mukit09

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 08:12:56