java - DynamoDB Spring Boot 数据剩余 "PersistentEntity must not be null!"

标签 java spring spring-boot amazon-dynamodb spring-data-rest

我正在使用 DynamoDB 构建 Spring Boot 应用程序。我想添加 Spring Data REST。数据层有效,但 REST 无法映射实体。它正确地解析并创建了 REST 端点,但我收到了 PersistentEntity must not be null! 消息和访问 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

当我调试代码时,我看到 PersistentEntityResourceAssembler 中的 entities 是空的。这意味着我的实体没有注册。我猜这是因为它们不是常规的 JPA 实体,它们仅通过存储库链接到数据层。

我如何让 Spring 了解我的实体,以便使 Data REST 框架与 DynamoDB 一起工作?

以下是我项目的相关部分。代表 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;
    }
}

存储库:

public interface TesterRepository extends CrudRepository<Tester, String> {

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

配置类:

@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;
    }

}

和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'

代码已经简化,其余的可以在这个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 ,但它将 JPA 和 Hibernate 添加到我想避免的类路径中,因为我不需要它们。

最佳答案

我还使用 spring boot 和 dynamo db 开发了应用程序,但我从未遇到过这个问题。在开发应用程序时,我引用了以下示例。

Git Dynamo db Spring Boot Spring Data Example

关于java - DynamoDB Spring Boot 数据剩余 "PersistentEntity must not be null!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41916619/

相关文章:

Java Selenium Webdriver : Element not clickable

java - 为什么不使用所有进口?

java - 在 Eclipse Virgo 中选择 Sun JAX-WS 实现而不是 CXF 实现

java - 仅当特定对象具有可比较性时设置排序

spring - 用于 HikariCP + Spring + MS SQL Server 的 JTDS 配置

java - 不满意的依赖异常 : Error creating bean with name 'repository.BookRepositoryTest' in Junit Test

java - Spring Webflux 响应式(Reactive) Mongo 批量操作 (Java)

java - 如何在rest api中编写自定义验证?

java - Hibernate ManyToMany 方法抛出 'org.hibernate.LazyInitializationException' 异常

spring-boot - 使用 Spring Security OAuth 时 Spring Boot Reactive WebClient "serverWebExchange must be null"