小编Mil*_*lad的帖子

如何在 Spring Boot 中建立来自不同微服务的两个实体之间的关系?

我正在尝试使用微服务架构制作一个简单的Spring Boot Web 应用程序。

我有两个微服务,其实体定义如下:

Microservice 1 :

@Entity
public class Article {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String title;

    private String Content;

}
Run Code Online (Sandbox Code Playgroud)

Microservice 2 :

@Entity
public class Tag {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String title;
}
Run Code Online (Sandbox Code Playgroud)

现在我想在我的Gateway中的这两个实体之间建立多对多关系。

我曾尝试使用 feign 客户端,如下所示:

Gateway :

@FeignClient(value = "article-service")
public interface ArticleClient {

    @RequestMapping(value = "/articles/", method = RequestMethod.GET)
    Set<Article> getArticleById(@RequestParam("id") Long id);

}

@FeignClient(value = …
Run Code Online (Sandbox Code Playgroud)

spring-data spring-data-jpa spring-boot microservices

5
推荐指数
1
解决办法
5855
查看次数