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

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

<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 启动运行。java

<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提供的父项目。那么如何解决呢?git

  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快速入门程序同样,启动类和测试步骤均同样。github

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

源代码连接:https://github.com/myNameIssls/springboot-studyspring

相关文章
相关标签/搜索