一、多模块建立
1、父工程创建
可以选这个模式,这个只生成pom,把需要springboot组件选上,一般springboot共用就行
image.png
2、子web工程1创建
springboot 创建,不选任何组件,删除生成自动生成dependenc
image.png
image.png
image.png
这边什么组件都不选
image.png
把dependencies中删除,共用父pomjar包,详情见下面配置
image.png
3、子web工程2创建
和上面一样
4、service工程创建
service不需要启动包,选这个就行
image.png
二、配置
1、父pom配置module,以springboot方式创建要手动加,maven方式系统给加了
image.png
2、子pom依赖父pom
image.png
image.png
3、web子模块加载service模块
my.version是父pom统一命名版本,方便管理
image.png
image.png
三、打包
1、父pom和service模块pom去除下方打包配置,否则会出现循环依赖打包
详情参考:https://blog.csdn.net/weixin_40709965/article/details/108179978
image.png
2、父pom添加package为pom,service模块添加package为jar
image.png
image.png
3、这时去server1或者2打包提示没有service的jar包,所以先去父模块中install
image.png
3、install 会把server1 server2也打成jar包,若不需要,则在server1和2中配置如下
image.png
4、在server1或者server2中package则可打包web模块了
image.png
四、疑问
每次更新service模块需要父模块install下,是否可以在server1或者server2中package时先执行下install父模块?
答:可以使用命令 mvn clean insatll -pl server1 -am 打包子模块,会自动install依赖包