先新建一个Spring Boot空项目,填好信息后直接下一步,然后点击finish
将项目里面多余的文件删除,留一个pom.xml文件就够够的了
2、创建子模块在父模块的基础上创建模块
创建了两个子模块,demo1和demo2
将子模块中多余的部分文件删干净
3、配置 父工程配置设置父工程打包为pom,并引入子模块,pom.xml如下:
子模块配置4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.2 com.yuyun springboot-02 1.0.1 springboot-02 springboot 多模块项目 pom demo1 demo2 1.0.1 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test
子模块打包为jar,并继承父模块
4、子模块之间的代码引用4.0.0 springboot-02 com.yuyun 1.0.1 demo1 jar ${project.artifactId} org.springframework.boot spring-boot-maven-plugin
例如:demo2调用demo1的实体类或方法
在demo2的pom.xml文件中添加
com.yuyun demo1 ${demo-version}
添加后demo2的pom.xml内容如下:
4.0.0 springboot-02 com.yuyun 1.0.1 demo2 jar com.yuyun demo1 ${demo-version} ${project.artifactId} org.springframework.boot spring-boot-maven-plugin
demo地址:https://gitee.com/hyh17808770899/spring-boot/tree/master/springboot-02



