1.父模块中的配置.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 在父模块中, 不再引用springboot的父坐标配置, 这里直接使用自己的父坐标配置 -->
<parent>
<groupId>com.carl.study</groupId>
<artifactId>xx-yy</artifactId>
<version>xxxx</version>
</parent>
<!--<parent>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-parent</artifactId>-->
<!--<version>2.1.6.RELEASE</version>-->
<!--<relativePath/> <!– lookup parent from repository –>-->
<!--</parent>-->
<groupId>com.carl.study.springcloud</groupId>
<artifactId>cloud-demo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>cloud-demo-parent</name>
<description>Demo project for Spring Boot</description>
<!-- 添加dependencyManagement配置, 并引入spring-boot相关配置 -->
<dependencyManagement>
<dependencies>
<!-- 替换在parent标签中引入spring-boot-starter-parent的配置 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- 其他公共jar包 -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.6.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.6.RELEASE</version>
<!-- 项目重新启动 -->
<configuration>
<fork>true</fork>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
2. 子模块中的配置, 父模块中的相应修改会导致打包后的jar包不能在直接使用java -jar运行, 会提示找不到主类(因打包的时候没有执行spring-boot-maven-plugin的repackage目标)
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 项目重新启动 -->
<configuration>
<fork>true</fork>
<includeSystemScope>true</includeSystemScope>
</configuration>
<!-- 解决java找不到主类的问题 -->
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
加上repackage目标后的主要日志记录变化:
修改后, 子模块中相关的配置可能引用不到, 可以先注释掉子模块中关于springboot的配置, 待其加载完成后, 重新打开.