问题描述
我正在从事 Spring Boot、Hibernate、Thymeleaf 项目,我对实现重用实体层的最佳架构感到有些困惑.
I am working on a Spring Boot, Hibernate, Thymeleaf project, I'm a bit confused to achieve the best architecture to reuse my entity layer.
我有 2 个 Maven 父项目,我想通过创建一个 ProjectEntity(在两个父项中重用它)来实现以下项目层次结构
I have 2 Maven parent projects, I want to achieve the below project hierarchy with just creating one ProjectEntity (reusing it in both parents)
ProjectAPIParent
ProjectAPIParent
a) 项目实体
b) 项目存储库
c) 项目API
ProjectClientUIParent
ProjectClientUIParent
a) 项目实体
b) ProjectClientUI
b) ProjectClientUI
问题是一个子项目不能有多个父项.
The problem is one child project cannot have multiple parents.
现在,我可以选择只创建一个基础父项目,但问题是这听起来不正确,因为我想要客户端和服务器端项目之间的完全松散耦合.
Now, I have an option of creating one base parent project only but the problem is that it doesn't sound right because I want full loose coupling between client side and the server side projects.
在这种情况下你会建议我做什么?
What would you suggest me to do in this case?
您的意见很重要.谢谢:)
Your opinion will matter a lot. Thanks :)
推荐答案
做出这种决定并没有真正的惯用规则.
There is not really an idiomatic rule to take this kind of decision.
就个人而言,我选择与工件表现出最强自然所有权关系的项目作为工件的父项.
Personally, I select as parent of an artifact, the project that manifests the strongest natural ownership relationship with.
例如,如果 ProjectEntity
源代码设计为仅供 ProjectAPIParent
项目的开发人员修改并随同发布,ProjectAPIParent
应该是很可能是 ProjectEntity
模块的 Maven 父级(以及它的聚合器 pom).而 ProjectClientUIParent
应该使用 ProjectEntity
作为依赖项.
For example if the ProjectEntity
source code is designed to be modified only by developers of the ProjectAPIParent
project and released with, ProjectAPIParent
should be very probably the Maven parent (as well as its aggregrator pom) of the ProjectEntity
module. And ProjectClientUIParent
should so use ProjectEntity
as a dependency.
但是,如果您无法清楚地识别出与此工件拥有这种关系的父项目,则您可能不应该将 ProjectEntity
设为它们中的任何一个的子项.
在这种情况下,让 ProjectEntity
成为这两个项目的依赖更有意义.
But if you don't manage to identify clearly a parent project that owns such a relationship with this artifact, you should probably not make ProjectEntity
a children of none of them.
In this case, making ProjectEntity
a dependency of this two projects makes more sense.
作为旁注,无论您为父 pom 选择什么,您都可以在 ProjectAPIParent 的聚合器 pom.xml 中将
和 ProjectEntity
定义为 Maven 模块(不要与 Maven 子模块混淆)ProjectClientUIParent
.
As a side note, whatever your choice for the parent pom, you may define ProjectEntity
as Maven modules (to not mix up with Maven children) in the aggregrator pom.xml of ProjectAPIParent
and ProjectClientUIParent
.
这篇关于Java - Maven - 在客户端和服务器端项目中重用实体层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!