[英]Use user entity with additional data in a jhipster microservice
im currently working on a Jhipster project.我目前正在做一个 Jhipster 项目。 i have the jhipster uaa set up, to register users(default implementation).
我设置了 jhipster uaa 来注册用户(默认实现)。 now i want to create a userService (jhipster microservice) which acts like an api for user profiles.
现在我想为用户配置文件创建一个用户服务(jhipster 微服务),其作用类似于 api。 I already created an userprofile entity which should extend the default user entity.
我已经创建了一个应该扩展默认用户实体的用户配置文件实体。 I am also able to assign a user to a userprofile via the gateway (i`m not shure if this is working properly),but now i got a few problems/things i dont understand:
我还可以通过网关将用户分配给用户配置文件(如果这工作正常,我不放心),但现在我遇到了一些我不明白的问题/事情:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Unknown entity name: org.springframework.security.core.userdetails.User
but i'm not shure if this example is for a microservice usecase.但如果这个例子是针对微服务用例的,我不放心。 This also only happens if i delete the
@GeneratedValue(strategy = GenerationType.IDENTITY)
annotation above the id value.这也只有在我删除 id 值上方的
@GeneratedValue(strategy = GenerationType.IDENTITY)
注释时才会发生。
do i actually need a seperate userservice to fetch the "extended" user entity (userprofiles)?我真的需要一个单独的用户服务来获取“扩展”用户实体(用户配置文件)吗? I´m thinking, that the userservice-api returns the userprofile( which should share the user id with the user entity).
我在想,userservice-api 返回用户配置文件(它应该与用户实体共享用户 ID)。
I want to add additional fields to the user registration form (username,adress,postalCode,city).我想在用户注册表单中添加其他字段(用户名、地址、邮政编码、城市)。 is it possible to use this information to create a default user entity, as well as an extended userprofile which is handled by my microservice?
是否可以使用此信息来创建默认用户实体以及由我的微服务处理的扩展用户配置文件?
I appreciate any help, since this is a pretty important project.我感谢任何帮助,因为这是一个非常重要的项目。 please let me also know, if i got something about the jhipster microservice "mechanics" wrong.
如果我对 jhipster 微服务“机制”有什么误解,请告诉我。 I should note, that i'm at beginner level with spring development, so sorry if i'm missing something obvious.
我应该注意,我在 spring 开发方面处于初学者水平,如果我遗漏了一些明显的东西,很抱歉。
I think a DTO would be the most efficient solution.我认为 DTO 将是最有效的解决方案。 Jhipster already integrates Mapstruct.
Jhipster 已经集成了 Mapstruct。 You create a dto that you pass to your service layer when creating a new user then the mapper does the mapping to have the defaultUser and persist it.
您创建一个 dto,在创建新用户时传递给您的服务层,然后映射器执行映射以拥有 defaultUser 并将其持久化。 I advise you to read the Mapstruct doc or examples on the Jhipster website, here is the link: https://www.jhipster.tech/using-dtos/
我建议您阅读 Jhipster 网站上的 Mapstruct 文档或示例,这是链接: https://www.jhipster.tech/using-dtos/
Okay, so i figured out a solution.好的,所以我想出了一个解决方案。 For anyone dealing with this kind of problem: I looked again at the solution provided by jhipster: https://www.jhipster.tech/tips/022_tip_registering_user_with_additional_information.html
对于任何处理此类问题的人:我再次查看了 jhipster 提供的解决方案: https://www.jhipster.tech/tips/022_tip_registering_user_with_additional_information.html
which is a bit outdated, but in general its still working.这有点过时了,但总的来说它仍然有效。 The problem was, that files moved locations and changed some methods (which i didnt notice earlier), but the principle is still applicable.
问题是,文件移动了位置并更改了一些方法(我之前没有注意到),但原理仍然适用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.