spring boot 不使用parent

编程知识 更新时间:2023-04-05 04:37:05

创建 spring-boot 应用通用方法是配置 pom.xml,定义 为 spring-boot-start-parent。如下:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.4.0.RELEASE</version>
</parent>
<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

但是在真正的项目开发中,往往模块需要定义自己的 而 maven 的 pom 只允许一个 存在,这种情况下,可以采用下面的定义来避免使用 spring-boot-start-parent。安装如下配置的 pom.xml 可以通过 maven package 生成可以运行的 jar 包,通过 java -jar xxxx.jar 启动运行。

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>1.4.0.RELEASE</version>
  </dependency>

  <!--ImportdependencymanagementfromSpringBoot-->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>1.4.0.RELEASE</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.4.0.RELEASE</version>
      <configuration>
        <executable>true</executable>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>repackage</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>

</build>

更多推荐

spring boot 不使用parent

本文发布于:2023-04-05 04:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/713d649f15e66980ec32c07acc01944f.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:spring   boot   parent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 44807文章数
  • 14阅读数
  • 0评论数