简体   繁体   English

DynamoDB Spring Boot数据休息“PersistentEntity不能为空!”

[英]DynamoDB Spring Boot Data Rest “PersistentEntity must not be null!”

I am building a Spring Boot application with DynamoDB. 我正在使用DynamoDB构建Spring Boot应用程序。 I wanted to add Spring Data REST. 我想添加Spring Data REST。 The data layer works, but the REST fails on mapping of the entities. 数据层有效,但REST在实体映射时失败。 It correctly resolves and creates the REST endpoint but I am getting PersistentEntity must not be null! 它正确地解析并创建了REST端点但我得到的PersistentEntity不能为null! message and an exception when accessing the REST API: 访问REST API时的消息和异常:

java.lang.IllegalArgumentException: PersistentEntity must not be null!
    at org.springframework.util.Assert.notNull(Assert.java:115)
    at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.<init>(PersistentEntityResource.java:140)
    at org.springframework.data.rest.webmvc.PersistentEntityResource$Builder.<init>(PersistentEntityResource.java:123)
    at org.springframework.data.rest.webmvc.PersistentEntityResource.build(PersistentEntityResource.java:115)
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.wrap(PersistentEntityResourceAssembler.java:74)
    at org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler.toResource(PersistentEntityResourceAssembler.java:55)
    at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.entitiesToResources(AbstractRepositoryRestController.java:133)
    at org.springframework.data.rest.webmvc.AbstractRepositoryRestController.toResources(AbstractRepositoryRestController.java:80)
    at org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(RepositoryEntityController.java:212)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)

removed irrelevant parts of the exception

When I debug the code, I see that the entities in PersistentEntityResourceAssembler is empty. 当我调试代码时,我发现PersistentEntityResourceAssembler中的entities是空的。 It means my entities were not registered. 这意味着我的实体没有注册。 I guess this is because they are not regular JPA entities and they are only linked through the repositories to the data layer. 我想这是因为它们不是常规的JPA实体,它们只通过存储库链接到数据层。

How do I let Spring know about my entities in order to make the Data REST framework work with DynamoDB? 我如何让Spring了解我的实体,以使Data REST框架与DynamoDB一起使用?

Here are relevant parts from my project. 这是我项目的相关部分。 The dummy entity representing a table in dynamo: 表示发电机中的表的虚拟实体:

@DynamoDBTable(tableName = "DummyTable")
public class Tester {
    @Id
    private String id;


    @DynamoDBHashKey(attributeName = "id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}

The repository: 存储库:

public interface TesterRepository extends CrudRepository<Tester, String> {

    @EnableScan
    @Override
    Iterable<Tester> findAll();
}

The config class: 配置类:

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

// deleted params

    @Bean
    public AmazonDynamoDB amazonDynamoDB() {
// deleted the simple initializer, just long code
        return amazonDB;
    }

}

And gradle dependencies: 和gradle依赖:

compile 'com.amazonaws:aws-java-sdk-core:1.11.86'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-data-rest'
compile 'com.github.derjust:spring-data-dynamodb:4.4.1'

The code has been simplified, the rest can be found in this gist with all files needed to build the whole application . 代码已经简化,其余的可以在这个要点中找到构建整个应用程序所需的所有文件

I tried to follow the demo from the original author of the Spring Data DynamoDB library , but it adds JPA and Hibernate to the classpath which I want to avoid as I should not need any of it. 我试图按照Spring Data DynamoDB库的原始作者的演示 ,但它将JPA和Hibernate添加到我想要避免的类路径中,因为我不需要任何它。

I also developed app with spring boot and dynamo db but I never face this issue . 我还用spring boot和dynamo db开发了应用程序,但我从未遇到过这个问题。 While developing application I refer below example. 在开发应用程序时我参考下面的示例

Git Dynamo db Spring Boot Spring Data Example Git Dynamo db Spring Boot Spring数据示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “PersistentEntity不能为null”MongoDB和Spring Data REST的异常 - “PersistentEntity must not be null” Exception with MongoDB and Spring Data REST SPRING DATA REST PROJECTIONS,osdrwRepositoryRestExceptionHandler:PersistentEntity不能为null - SPRING DATA REST PROJECTIONS, o.s.d.r.w.RepositoryRestExceptionHandler : PersistentEntity must not be null spring data rest mongodb java.lang.IllegalArgumentException:PersistentEntity不能为null - spring data rest mongodb java.lang.IllegalArgumentException: PersistentEntity must not be null 如何使Spring Data @Async工作? 错误:PersistentEntity不能为null - How to make spring data @Async work? Error: PersistentEntity must not be null Spring 引导 rest API - Querydsl,谓词不能是 null - Spring boot rest API - Querydsl, predicate must not be null 什么是Spring Data的PersistentEntity? - What is Spring Data's PersistentEntity? Spring Boot - 源不能为空 - Spring Boot - Source must not be null Spring Data Rest (SDR) 错误? 持久实体不能为空 - Spring Data Rest (SDR ) bug? Persistent Entity Must not be null Spring Data Mongo 找不到 Enum 的 PersistentEntity - Spring Data Mongo cannot find PersistentEntity for Enum IllegalStateException:目标对象不能为null Spring Boot - IllegalStateException:Target object must not be null Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM