2017-04-05 9 views
0

私は2つのスプリングブートアプリケーション、休憩リソースを備えたサーバーサイドスプリングブートマイクロサービス、およびファインクライアントを使用するクライアントサイドスプリングブートマイクロサービスアプリをHATEOASフィードを消費するように構築しました。Spring Boot RepositoryRestResource with FeignClient

私は、両側に2つのエンティティオブジェクトAggregateとGatewayを持っています。ゲートウェイが集約オブジェクト内にある

ゲートウェイオブジェクト用の@RepositoryRestResourceインターフェイスがない限り、Aggregateを介してゲートウェイオブジェクトを取得できますが、注釈がある場合、クライアントの集約オブジェクトにリストされているゲートウェイを取得できません側。ゲートウェイ側のJson構造ではなく、サーバー側のHATEOASフィードがGateway用のリンクをAggregate上に追加するためです。

ゲートウェイオブジェクトの@RepositoryRestResourceインターフェイスを持っている間に、私はまだAggregateオブジェクトからゲートウェイオブジェクトを取得できますか?あるいは、リンクからゲートウェイオブジェクトを埋めるようにFeign Clientを設定する方法はありますか?

例.. GatewayRepository

[ 
    { 
    "id": "a65b4bf7-6ba5-4086-8ca2-783b04322161", 
    "gateway": null, //<-- Gateway is null here 
    ....... 

上@RepositoryRestResource注釈付きhttp://localhost:9999/aggregates/

クライアントからサーバーhttp://localhost:8000/aggregates/

からGatewayRepository

[ 
    { 
    "id": "a65b4bf7-6ba5-4086-8ca2-783b04322161", 
    "gateway": { //<-- Gateway id and properties are there now on Aggregate object 
     "id": "4a857a7a-2815-454c-a271-65bf56dc6f79", 
    ....... 

上@RepositoryRestResource注釈なしここでGatewayRepository

"_embedded": { 
    "aggregates": [ 
     { 
     "id": "b5171138-4313-437a-86f5-f70b2b5fcd22", 
     "gateway": { //<-- Gateway id and properties are there now on Aggregate object 
      "id": "3608726b-b1b1-4bd4-b861-ee2bf5c0cc03", 
     ....... 

上@RepositoryRestResource注釈なしGatewayRepository

{ 
    "_embedded": { 
    "aggregates": [ 
     { 
     "id": "a65b4bf7-6ba5-4086-8ca2-783b04322161", 
     "_links": { 
      "self": { 
      "href": "http://localhost:8000/aggregates/a65b4bf7-6ba5-4086-8ca2-783b04322161" 
      }, 
      "gateway": { //<-- Gateway becomes a link here 
      "href": "http://localhost:8000/aggregates/a65b4bf7-6ba5-4086-8ca2-783b04322161/gateway" 
      }, 
     ....... 

上@RepositoryRestResource注釈付き

は、モデルの私のサーバー側の実装が

@Entity 
class Aggregate extends TemplateObject { 
    @OneToOne(cascade = CascadeType.MERGE) 
    private Gateway gateway; 
    ....... 
} 

@Entity 
class Gateway extends TemplateObject { 
    @NotNull 
    @Column(unique = true) 
    private String name; 
    ....... 
} 

をオブジェクトとサーバー側の残りのリポジトリがあります

私はモデルDTO上の同じ注入が

class Gateway extends TemplateObject { 
    @NotNull 
    private String name; 
    ....... 
} 

class Aggregate extends TemplateObject { 
    private Gateway gateway; 
    ....... 
} 

そして装うクライアントこれら装うを使用して

@FeignClient("billing-service/gateways") 
interface GatewayService extends GenericService<Gateway> { 
} 

@FeignClient("billing-service/aggregates") 
interface AggregateService extends GenericService<Aggregate> { 
} 

を(オブジェクト持つクライアント側(ポート8000​​上でこれらの休息リソースの使用)

クライアントのポート9999クライアントコントローラ)

おかげさまで、どんなアドバイスや提案も大いにありがたいです

答えて

1

あなたの残りのレポジトリと一緒に投影を見てみてください - hereを見てください。その後、それぞれの投影をパラメータとして提供するために、FeignClient要求パスを適合させるだけです。

+0

多くのありがとう、投影は私のためにうまくいった:) –