创建父项目
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