五、建立 Spring Boot 项目时,当父依赖不再是 spring-boot-starter-parent 怎么办

(一)问题
  现阶段建立 Spring Boot 项目,使用 IDEA 自动创建项目时,会导入如下父依赖:

<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.6.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

  但在公司时,我们可能会需要自己公司内部的父依赖,那么就不能再依赖 spring-boot-starter-parent。但是若我们直接删除这个父依赖,就会报错(PS:主要是版本错误),遇到这种情况如何解决?

(二)解决办法
1、删除 spring-boot-starter-parent 依赖

2、在 dependencyManagement 标签下,添加 spring-boot-dependencies 依赖,并且版本保持和原 spring-boot-starter-parent 一致

<dependencyManagement>
		<dependencies>
			<!--
			    使用场景:当父依赖是公司内部依赖时(PS:不是spring-boot-starter-parent),需要
			这样做。
			 -->
			<!-- Spring Boot 依赖 -->
			<dependency>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-dependencies</artifactId>
				<version>2.0.6.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>

			<!-- Spring Cloud 依赖 -->
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

3、此时编译若报错,一般是编译插件版本问题,我们需要去 spring-boot-starter-parent 找到 编译插件,同时版本也拿过来

<!-- Maven Java 编译器插件 -->
			<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<!-- Maven Java 编译器插件 -->
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>${maven-compiler-plugin.version}</version>
			</plugin>

4、设置 编译源 和 编译后 Java 版本

		<java.version>1.8</java.version>
		<maven.compiler.source>${java.version}</maven.compiler.source>
		<maven.compiler.target>${java.version}</maven.compiler.target>
  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值