springboot项目如何使用自己的parent

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/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
    <!--</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的配置, 待其加载完成后, 重新打开. 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值