2017-01-29 3 views
4

私はDynamoDBでSpring起動アプリケーションを構築しています。私はSpring Data RESTを追加したいと思っていました。データレイヤは機能しますが、RESTはエンティティのマッピングに失敗します。それは正しく解決し、RESTエンドポイントを作成しますが、私はを取得しています。PersistentEntityはnullであってはなりません!メッセージやRESTのAPIにアクセスする例外は:私はコードをデバッグするときDynamoDB SpringブートデータRest "PersistentEntityをnullにすることはできません!"

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 

、私はPersistentEntityResourceAssemblerentitiesが空であることを参照してください。私の団体が登録されていないことを意味します。これは、JPAの正規のエンティティではなく、リポジトリを介してデータレイヤーにのみリンクされているためです。

どのように私は春がDynamoDBの持つデータRESTフレームワークの仕事をするために私の実体を知ってみましょうか?ここで

は私のプロジェクトから関連する部分です。ダイナモでテーブルを表すダミーエンティティ:

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

Configクラス:

@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を追加し、私はそれのいずれかを必要はありませんとして避けたいクラスパスに休止状態。

+0

私は同じ問題を抱えています。あなたは解決策を見つけましたか? –

+0

@EricZhang私はDynamoDB用のスプリングライブラリを使用していませんでした。私はこのプロジェクトで何をしたのかを見ることができます:https://github.com/sm4/promo-code – sm4

答えて

-2

私も春のブートとダイナモのdbでアプリを開発しましたが、私はこの問題に直面しません。アプリケーションの開発中に、私は以下の例を参照します。

Git Dynamo db Spring Boot Spring Data Example

関連する問題