错误信息
如果升级到Spring Boot 2.7.8,可以看到因为找不到mysql-connector-java依赖而出现错误。
配置:
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.14</version><relativePath/> <!-- lookup parent from repository -->
</parent><dependencies><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency>
</dependencies>
错误信息:
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 54, column 15@
[ERROR] The build could not read 1 project -> [Help 1]
原因
这是因为 Spring Boot 2.7.8 中 mysql-connector-java 不再由依赖管理来管理。
Release v2.7.8 · spring-projects/spring-boot · GitHub
处理
现有mysql的groupId:mysql-connector-java是一个遗留形式,用一个单词“mysql”维护了很长时间。
https://blogs.oracle.com/mysql/post/mysql-connectorj-has-new-maven-coordinates
8.0.31(2022年10月14日发布)和8.0.32(2023年1月18日发布)两个版本分别与mysql-connector-java/mysql-connector-j并行维护,今年春季boot 2.7.8 从那时起 mysql:mysql-connector-java 已从依赖管理中删除。
Maven Central Repository SearchOfficial search by the maintainers of Maven Central Repositoryhttps://search.maven.org/artifact/mysql/mysql-connector-java
Maven Central Repository SearchOfficial search by the maintainers of Maven Central Repositoryhttps://search.maven.org/artifact/com.mysql/mysql-connector-j
因此,从现在开始您可以使用 com.mysql:mysql-connector-j 依赖项。
自 Spring Boot 2.7.8 起,更改 mysql:mysql-connector-java -> com.mysql:mysql-connector-j 并删除 mysql-connector-java 依赖管理
<dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId>
</dependency>
参考
mysql:mysql-connector-java -> com.mysql:mysql-connector-j 변경 및 Spring Boot 2.7.8 이후 mysql-connector-java 의존성 관리 제거