Spring Java Maven 项目+模块设计 [英] Spring Java Maven Project + Module Design

查看:50
本文介绍了Spring Java Maven 项目+模块设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有的 java 项目转换为 maven 项目.我有以下方法,但我不确定我是否朝着正确的方向前进.

I am trying to convert an existing java project into maven project. I have the following approach in mind, but I am not sure if I am heading in the right direction.

第一种方法是将所有实体、存储库、服务、常量、实现类分组到 1 个单独的 maven 模块/项目中.

The 1st approach is to group all the entities, repository, service, constants, implementation classes into 1 single maven module/project.

第二种方法是将所有服务类放在各自的 maven 模块/项目中,并将其余的实体、存储库类放到一个基本模块中.

The 2nd approach is to have all the service classes in their respective maven module/project and the rest of the entities, repository classes into a base-module.

我应该采用哪种方法?

方法一

finance-module
 - com.example.finance.entities 
 - com.example.finance.repository
 - com.example.finance.service

order-module
 - com.example.order.entities
 - com.example.order.repository
 - com.example.order.service

code-module
 - com.example.code.entities
 - com.example.code.repository
 - com.example.code.service

方法二

finance-module
 - com.example.finance.service

order-module
 - com.example.order.service

code-module
 - com.example.code.service

base-module
 - com.example.finance.entities  
 - com.example.finance.repository
 - com.example.order.entities
 - com.example.order.repository
 - com.example.code.entities
 - com.example.code.repository

推荐答案

您拥有的第一种方法是按功能创建文件夹的经典案例,而第二种方法是按类型创建文件夹(我应该称之为办法).尽管这两种方法各有利弊,但个人选择是按功能组织模块(方法 1).

The first approach you have is a classic case of having folders by feature vs the second approach where you have a kind of folders by type (should i call it that way). Although both approaches have pros and cons , a personal choice is to have the modules organized by feature (approach-1).

这是我的 2 美分为什么:

Here is my 2 cents as to why :

a) 随着应用程序大小的增长,当有很多包时,转到特定文件是一个问题.简而言之,导航问题.

a) As the size of application grows , going to a specific file is a problem when there are many packages. In short a navigation problem.

b) 你可以让多个团队独立地处理这些不同的模块,并且有一个父 pom,旨在让子 pom 的/模块为发布而构建,仍然保持代码分离

b) You can have multiple teams working on these different modules independently and have a parent pom designed to have the child pom's / modules built for a release still maintaining code seperation

c) 模块变得松散耦合 &封装,由于类 A-> B ,B->A 问题,其中一个更改很可能不会破坏另一个构建

c) Modules become loosely coupled & encapsulated , chances are changes in one do not break the other builds because of the class A-> B , B->A problem

这篇关于Spring Java Maven 项目+模块设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆