2017-04-05 6 views
0

저는 휴식 자원을 사용하는 서버 측 스프링 부팅 마이크로 서비스와 Feign 클라이언트를 사용하는 클라이언트 측 스프링 부팅 마이크로 서비스 응용 프로그램 HATEOAS 피드를 생성했습니다.FeignClient가 포함 된 Spring Boot RepositoryRestResource

두 개체 개체 Aggregate 및 Gateway가 양쪽에 있습니다. 게이트웨이 내부에 집합 개체

게이트웨이 개체에 대한 @RepositoryRestResource 인터페이스가없는 한 집계를 통해 게이트웨이 개체를 검색 할 수 있지만 주석이 있으면 클라이언트의 집계 개체에 나열된 게이트웨이를 가져올 수 없습니다. 측면. 서버 측 HATEOAS 피드가 게이트 웨이에 대한 Json 구조 대신 Aggregate에 대한 링크를 추가하기 때문에 이것이 나타났습니다.

어쨌든 게이트웨이 객체에 @RepositoryRestResource 인터페이스가있는 동안 Aggregate 객체에서 Gateway 객체를 얻을 수 있습니까? 아니면 링크에서 게이트웨이 객체를 채우도록 Feign Client를 구성 할 수 있습니까?

예 .. GatewayRepository

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

에 @RepositoryRestResource 주석으로 클라이언트 http://localhost:9999/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 주석없이 http://localhost:8000/aggregates/

,536,913 GatewayRepository

에 @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 주석으로 63,210

여기

"_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", 
     ....... 

모델의 내 서버 측 구현

@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

많은 감사, 예상은 나를 위해 잘 작동했습니다. :) –