使用maven构建springboot


一、spring-boot-starter-parent的作用

怎样使用spring-boot-starter-parent

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>	
<version>2.1.0.RELEASE</version> </parent> 

首先spring-boot-starter-parent是一个项目。它有以下几个特点:

  1. java1.8 作为默认编译水平
  2. 这个依赖部分基础与spring-boot-dependences(用以管理公用依赖的版本)。这样在我们自己的dependency中,我们就可以不用写<version>……</version>了。
  3. 带有repackage execution id的可以执行的repackage goal(这个包可以执行)。
  4. 有效的资源过滤
  5. 有效的插件配置
  6. 对application.properties 和 application.ym进行有效的资源过滤。

二、不要parent的构建springboot项目

如果你不想使用spring-boot-starter-parent,通过设置scope=import的依赖,你仍能获取到依赖管理的好处。
比如:

	<dependencyManagement>
		<dependencies>
			<dependency>
				<!-- Import dependency management from Spring Boot -->
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>2.1.0.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

注意 spring-boot-dependencies 有它自己的标签( <dependencyManagement> )。如果你将所有的dependency放到<dependencies>,那么你对丢失这些引入(就是找不到maven Dependencies)。

三、参考

springboot reference document
springboot中文参考指南
不要parent时解决依赖丢失

猜你喜欢

转载自blog.csdn.net/wobushixiaobailian/article/details/84435946