Idea创建 Spring Boot & maven 多模块项目 &打war包部署

创建父项目

File=>New=>Project

在这里插入图片描述

删除src文件夹和其他多余文件

删除前
在这里插入图片描述
删除后
在这里插入图片描述

pom文件修改

修改打包类型

<packaging>pom</packaging>

删除pom文件maven插件

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

添加子模块auth、core

File=>New=>Module

在这里插入图片描述
在这里插入图片描述

修改pom文件

auth和core的pom文件

<parent>
    <groupId>com.qcby.lxt</groupId>
    <artifactId>mparent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

父模块的pom文件

<modules>
    <module>auth</module>
    <module>core</module>
</modules>

修改完毕效果

添加代码测试

AuthController

在这里插入图片描述

CoreController

在这里插入图片描述

*启动类相关

启动类调整

直接启动auth或者core中的启动类无法,加载到其他模块的类,需调整启动类至,com.qcby.lxt包下,以auth模块为启动模块示例。
Spring Boot默认只加载和启动类同级以及子包内的Bean。

在这里插入图片描述

pom文件修改

引用core模块

<dependency>
    <groupId>com.qcby.lxt</groupId>
    <artifactId>core</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

启动测试

http://localhost:8080/auth/hello
==============结果==========================
hello world auth!
========================================
http://localhost:8080/core/hello
===============结果=========================
hello world core!

打war包部署

修改启动类

@SpringBootApplication
public class AuthApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(AuthApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(AuthApplication.class);
    }
}

删除非入口项目的启动类

eg:CoreApplication

修改pom文件

修改打包类型

<packaging>war</packaging>

添加跳过测试配置

<properties>
    <skipTests>true</skipTests>
</properties>

删除非启动模块的maven插件

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

maven插件打包

双击idea中maven插件父模块
在这里插入图片描述

打包结果

[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ mauth ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-war-plugin:3.1.0:war (default-war) @ mauth ---
[INFO] Packaging webapp
[INFO] Assembling webapp [mauth] in [C:\Users\Administrator\Desktop\讲课\0417\mparent1\mauth\target\mauth-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [114 msecs]
[INFO] Building war: C:\Users\Administrator\Desktop\讲课\0417\mparent1\mauth\target\mauth-0.0.1-SNAPSHOT.war
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.5.RELEASE:repackage (default) @ mauth ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for mparent1 0.0.1-SNAPSHOT:
[INFO] 
[INFO] mparent1 ........................................... SUCCESS [  0.004 s]
[INFO] mcore .............................................. SUCCESS [  1.130 s]
[INFO] mauth .............................................. SUCCESS [  1.807 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.156 s
[INFO] Finished at: 2021-04-17T17:58:37+08:00
[INFO] ------------------------------------------------------------------------

源码地址

传送门:github

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三师兄东流

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值