不使用 spring-boot-starter-parent 构建 spring boot 应用

创建 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>
版权声明:本文为崔瑜原创文章,未经博主允许不得转载。 http://blog.csdn.net/cuiy6642/article/details/52131399
 
 

需求描述:SpringBoot快速入门, 这篇博客记录如何使用SpringBoot快速创建一个HelloWorld程序。其中,在pom文件中,使用的SpringBoot提供的父依赖项目。在真实的企业级项目,我们可能会有自己的父项目,不想依赖Spring提供的父项目。那么如何解决呢?

  1. 第一步:修改pom文件,将原来的parent节点替换成如下依赖即可:
<dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>1.4.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

        </dependencies>
    </dependencyManagement>

其余配置和SpringBoot快速入门程序一样,启动类和测试步骤均一样。

参考链接:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/reference/htmlsingle/#using-boot-maven-without-a-parent

源代码链接:https://github.com/myNameIssls/springboot-study

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/myNameIssls/article/details/54613426
原文地址:https://www.cnblogs.com/yaowen/p/8622507.html