前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >springboot03 非parent方式搭建

springboot03 非parent方式搭建

作者头像
潇洒
发布2023-10-20 11:32:03
1960
发布2023-10-20 11:32:03
举报
文章被收录于专栏:石头岛

简述

项目中通过maven集成 springboot 有两种方式:

  1. 继承parent 方式
  2. 非继承 parent 方式

上一篇文章已经介绍过通过直接继承springboot项目座标的方式继承,这次说明如何通过非直接继承的方式构建springboot项目。

非parent 方式

推荐使用这种方式。 这样就可以使子项目使用 parent 标签了。

这种方式也比较直观,这里需要两个项目进行搭建测试

  1. parent 项目,需要被继承
  2. childen 项目,即需要继承 parent 项目,又需要springboot项目座标构建项目。

parent 项目配置

添加一个 spring boot 依赖,dependencyManagement 中的 springboot 就是核心,是springboot 官方提供的依赖,它是一组springboot的完整依赖座标,根据需要进行引用。 type 是 pom,scope 是 import,这种类型的 dependency 只能在 dependencyManagement 标签中声明。

代码语言:javascript
复制
<?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">
    <parent>
        <artifactId>springboottest-pom</artifactId>
        <groupId>com.liukai</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <packaging>pom</packaging>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>parent</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.5.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

childen 项目配置

parent 就可以使用普通的父项目了,而只需要进行 spring boot 的普通依赖即可。

代码语言:javascript
复制
<?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>
    <packaging>jar</packaging>
    <parent>
        <groupId>com.liukai</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

    <artifactId>children</artifactId>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

</project>

springboottest 项目配置

代码语言:javascript
复制
<?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>

    <groupId>com.liukai</groupId>
    <artifactId>springboottest-pom</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>children</module>
        <module>parent</module>
    </modules>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

</project>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-10-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简述
  • 非parent 方式
  • parent 项目配置
  • childen 项目配置
  • springboottest 项目配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档