我收到以下错误
java.lang.NoClassDefFoundError:无法初始化类org. springframework. data. mongodb. core. convert.
我正在将springboot升级到2.6.6,将springframework升级到5.3.18,我还添加了spring-data-mongodb依赖版本:3.3.3
详细堆栈跟踪:
原因:java. lang. NoClassDefFoundError:无法初始化类组织. springframework. data. mongodb. core. convert.在组织. springframework. boot. autoconfigure. data. mongo. mongo.数据配置. mongo自定义转换(Mongo数据配置. java:63)在sun. reflect.生成的方法访问器342.调用(未知源)在sun. reflect.指定的方法访问器实现调用(指定的方法访问器实现. java:43)在组织. springframework. beans.工厂.支持.简单示例化策略.示例化(简单示例化策略. java:154)... 75更多
POM中的Spring相关性为:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.18</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jcl</artifactId>
<version>5.3.18</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.6.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.3.3</version>
</dependency>
and in properties file I have added :
<spring-data-commons.version>2.6.0</spring-data-commons.version>
<spring-data-mongodb.version>3.3.3</spring-data-mongodb.version>
<spring-boot.version>2.6.6</spring-boot.version>
<spring.version>${spring-boot.version}</spring.version>
2条答案
按热度按时间wmtdaxz31#
此错误在添加以下依赖项后得到解决:
这是最新的bson版本,你可以添加一个版本兼容你的其他依赖.
qcuzuvrc2#
你能列出你的程序中所有的依赖项吗?下面是我的pom.xml的片段,我可以使用MongoCustomConversions没有任何问题。
Spring Boot:2.6.6Spring框架:5.3.18蒙古Spring Data b:3.3.3