Spring Boot 2.7.15中MongoDB Driver升级至4.7.0失败求助
MongoDB Driver 4.7.0升级失败问题求助
我正尝试将MongoDB Driver从4.6.1版本升级至4.7.0,但升级操作未成功。已使用Spring Boot 2.7.15版本进行尝试,仍无法完成升级。项目的Maven pom.xml配置如下,希望能得到协助解决该问题。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.agcs.cids</groupId> <artifactId>SampleService</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>SampleService</name> <description>Project for SampleService Service</description> <properties> <java.version>1.8</java.version> <springboot.version>2.7.15</springboot.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <surefire-plugin.version>2.22.0</surefire-plugin.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>${springboot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-rest</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <repositories> <repository> <id>spring-milestone</id> <name>Spring Maven MILESTONE Repository</name> <url>https://repo.spring.io/libs-milestone</url> </repository> </repositories> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <systemProperties> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> </systemProperties> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${springboot.version}</version> <configuration> <arguments> <source>1.8</source> <target>1.8</target> <uberJar>true</uberJar> </arguments> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <distributionManagement> <repository> <id>toolchain-nexus</id> <url>${nexus.release.url}</url> </repository> <snapshotRepository> <id>toolchain-nexus</id> <url>${nexus.snapshot.url}</url> </snapshotRepository> </distributionManagement> </project>
解决建议
- 强制指定MongoDB Driver版本:Spring Boot 2.7.15的parent pom默认管理的MongoDB Driver版本低于4.7.0,需手动覆盖版本:
在pom的<properties>节点中添加:
或者在<mongodb-driver.version>4.7.0</mongodb-driver.version><dependencyManagement>中直接声明MongoDB核心依赖版本:<dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-sync</artifactId> <version>4.7.0</version> </dependency> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-core</artifactId> <version>4.7.0</version> </dependency> - 排查依赖冲突:执行
mvn dependency:tree命令查看项目依赖树,确认是否有其他依赖强制引入了旧版本的MongoDB Driver,若有则通过<exclusions>标签排除冲突依赖。 - 刷新本地仓库:执行
mvn clean install -U命令,强制Maven更新依赖并清除本地仓库的缓存文件。
内容的提问来源于stack exchange,提问作者Rose
相关产品推荐
相关产品推荐

