I am creating a Spring boot application with DynamoDB. I wanted to add Spring Data REST. The data layer works, but REST does not work when displaying objects. It solves and creates the REST endpoint correctly, but I get PersistentEntity should not be null! message and exception when accessing the 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 entitiesin is PersistentEntityResourceAssemblerempty. This means that my objects have not been registered. I assume this is because they are not ordinary JPA entities, and they are only connected through repositories to the data layer.
How do I tell Spring about my entities to make the REST data structure work with 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 {
@Bean
public AmazonDynamoDB amazonDynamoDB() {
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 , .
Spring Data DynamoDB, JPA Hibernate classpath, , .