spring boot 父子项目的搭建(idea 搭建)

使用idea 搭建spring boot 父子项目

       项目结构:

  1.  先创建一个spring boot 父项目

后面依赖可以不用选

可以删除父项目的一些文件只剩入下图所示:(我idea 隐藏了一些文件,除了pom文件,应该还有两个没法删)

2. 创建子项目(spring-boot-child1,spring-boot-child2,spring-boot-child3,child1启动整个项目)

正常后面就是正常创建一个spring-boot项目(依赖添加一个web,子项目一定是在父项目文件夹下的)

3. child2 和child3 创建方法同child1 不在叙述

4. 项目都创建完成后,项目目录如下:

可以删除一些文件(child2,child3的启动类必须要删除,否则整个项目启动不起来)删除后项目目录如下:

5.修改pom文件

spring-boot-parent pom.xml 文件添加

pom文件如下:

<?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>
    <!-- spring boot 依赖 -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <!-- spring-boot-parent 项目信息  -->
    <groupId>com.ins.parent</groupId>
    <artifactId>spring-boot-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-parent</name>
    <description>Demo project for Spring Boot</description>

    <packaging>pom</packaging>

    <modules>
        <module>spring-boot-child1</module>
        <module>spring-boot-child2</module>
        <module>spring-boot-child3</module>
    </modules>

    <!-- 版本控制 -->
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

spring-boot-child1~child3 添加父依赖:

改成(每个需要修改):

在child1里spring boot 启动类上添加 (这个标红我很无奈,代码是没问题的)

6.启动项目---

7.写测试 child2 作为service ,child1为controll

spring-boot-child1 引入spring-boot-child2 依赖

controller 千万不要用lombook的依赖注入,那个会有点问题。

结果:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值