spring-boot-starter-jdbc和mysql-connector-j依赖爆红的解决办法
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
spring-boot-starter-jdbc和mysql-connector-j依赖爆红的解决办法
目录
出现问题之前
出现的问题
spring-boot-starter-jdbc和mysql-connector-j依赖爆红
解决办法
方案一
第一种是继承 spring-boot-starter-parent 然后 依赖覆盖
过查看 spring-boot-starter-parent-version.pom
源码可得 parent
的基本功能有
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
默认 Java 编译版本
指定编码格式
资源过滤自动过滤出 application*.yaml、application*.properties 等资源文件
打包相关配置
依赖管理可在项目中对公共依赖省略 version
标签。
继承 spring-boot-starter-parent
其实也算是继承自 spring-boot-dependencies
。parent 里面增加了一些插件然后指定了 maven 编译版本。
依赖覆盖
继承 parent
配置可以通过 property
覆盖内部的依赖。如在项目中升级 spring-boot-starter-jdbc
版本。
<properties>
<spring-boot-starter-jdbc.version>2.2.1.RELEASE</spring-boot-starter-jdbc.version>
</properties>
方案二
第二种是依赖 spring-boot-dependencies
通过 dependencyManagement
进行依赖管理
一般情况下企业都有自己的 parent
依赖包然后所有的项目都必须继承对应的 parent
包或者是项目有需要继承的自定义 pom 文件。这时候我们就可以通过这种方式使用 Spring Boot即直接依赖 spring-boot-dependencies
并定义好版本号再接下来在引用依赖时也就不用写版本号了。
但是关于打包的插件、编译的 JDK 版本、文件的编码格式等等这些配置在没有 parent 的时候这些统统要自己去配置。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
这两种方式我们在使用 spring-boot-starter
引入插件依赖时都不需要指定版本。