栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

创建Spring Boot多模块项目

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

创建Spring Boot多模块项目

1、创建父模块

先新建一个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.0.0

    
    
        springboot-02
        com.yuyun
        1.0.1
    

    demo1
    jar

    
        
        ${project.artifactId}
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    


4、子模块之间的代码引用

例如: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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/677982.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号