【发布时间】:2019-04-01 03:11:42
【问题描述】:
假设我有 2 个微服务:Service1 和 Service2。他们每个人都有自己的数据库。 Service1 有 EntityA,Service2 有 EntityB
EntityA {
Long id;
//other fields
EntityB entity;
}
EntityB{
//other fields
}
我正在使用 Spring 的 RestTemplate 来检索和保存数据。问题是:当从 Service1 的数据库中检索 EntityA 时,我没有 EntityB 的数据,因为它们保存在 Service2 的数据库中,我知道我应该通过 RestTemplate 进行休息调用以从 Service2 的数据库中检索 EntityB,但是两者之间的关系呢?实体 - EntityA 是否应该仍然在其中包含整个 EntityB 对象,即使它的字段大部分时间都是空的,除了 id ?我错过了什么? 先感谢您。
【问题讨论】:
标签: java spring web-services microservices