【发布时间】:2021-02-10 05:44:36
【问题描述】:
我正在使用微服务架构,我正在尝试创建一个 userApplication 实体,该实体具有仅用于凭据目的所需的所有数据,这意味着有关我的用户的基本信息,我还有另一个实体 userData,它具有所有我当前应用程序的数据,所以我真的不知道如何匹配这两个并在我创建 userApplication 实体时调用 userData 服务,因为每个人都有自己的微服务
我尝试使用 Feign,但不知道该怎么做。
//应用用户
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "BINARY(16)")
private UUID id;
@Column(unique = true, length = 20)
private String username;
private String normalizedUsername;
@Column(length = 60)
private String password;
private Boolean enabled;
private String firstname;
private String lastname;
@Column(unique = true, length = 100)
private String email;
private Boolean emailConfirmed;
private String normalizedEmail;
private String phonenumber;
private Boolean phonenumberConfirmed;
private Boolean twoFactorEnabled;
@OneToMany(mappedBy = "id")
@Column(name = "user_datum", table = "user_data")
private Collection<UserData> userDatum;
//用户数据
private String email;
private String firstname;
private String lastname;
private String address;
private LocalDate birthday;
private Double height;
private Double weight;
private String bloodType;
private String city;
private String country;
@ManyToOne()
@PrimaryKeyJoinColumn(name = "id")
private ApplicationUser user;
//存储库
@RepositoryRestResource(path = "users")
public interface UserRepository extends JpaRepository<ApplicationUser, UUID> {
public ApplicationUser findByUsername(String username);
public ApplicationUser CreateUserWithData ();
}
【问题讨论】:
-
我不太明白你的计划。您有两个相互连接的实体,但想在单独的微服务中管理它们?我认为这并没有什么意义,因为这样你就可以将应用程序的一个主题分散到多个微服务上。此外,我不知道 JPA 应该如何管理这些实体。您必须为两个微服务中的两个实体创建类,这听起来也很糟糕。目前我认为这两个部分应该在同一个微服务中。您是否有更多信息,例如错误消息?
标签: java spring jpa microservices feign