spring boot 创建多模块项目

1.创建父项目

父项目pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <!--基本信息-->
    <description>Spring boot 多模块项目</description>
    <modelVersion>4.0.0</modelVersion>
    <name>modules</name>
    <!--父类型都为pom类型-->
    <packaging>pom</packaging>

    <!--项目说明:这里作为聚合工程的父工程-->
    <groupId>com.modules</groupId>
    <artifactId>modules</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- 继承说明:这里继承SpringBoot提供的父工程 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <!-- 模块说明:这里声明多个子模块 -->
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>

    <!--java版本说明:使用的java版本-->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <!-- 版本说明:这里统一管理依赖的版本号 -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.module1</groupId>
                <artifactId>module1</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>com.module2</groupId>
                <artifactId>module2</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

2.创建子模块

在当前项目下右键,new module

子模块pom.xml

    模块一:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--基本信息-->
    <groupId>com.module1</groupId>
    <artifactId>module1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>module1</name>
    <description>模块一</description>

    <!-- 继承本项目的父工程 -->
    <parent>
        <groupId>com.modules</groupId>
        <artifactId>modules</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <!--模块一依赖模块二,引入依赖-->
        <dependency>
            <groupId>com.module2</groupId>
            <artifactId>module2</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

模块二:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--基本信息-->
    <groupId>com.module2</groupId>
    <artifactId>module2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>module2</name>
    <description>模块二</description>

    <!-- 继承本项目的父工程 -->
    <parent>
        <groupId>com.modules</groupId>
        <artifactId>modules</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        
    </dependencies>

</project>

这样module1就可以调用module2的内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值