在带有 MongoDB 的 Spring Boot M7 中找不到 ReflectKotlinClass

Posted

技术标签:

【中文标题】在带有 MongoDB 的 Spring Boot M7 中找不到 ReflectKotlinClass【英文标题】:ReflectKotlinClass not found in Spring Boot M7 with MongoDB 【发布时间】:2018-07-08 03:03:13 【问题描述】:

如果您使用 Web 和 MongoDB 模块在 start.spring.io 上创建新的 Spring Boot 项目,添加任何 @Document 注释类,此外将 kotlin.version 从 1.2.10 升级到 1.2.21,您会得到一个NoClassDefFoundError:

Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.0.M7:run (default-cli) on project demo: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 1; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'mappingMongoConverter' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mappingMongoConverter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/impl/load/kotlin/reflect/ReflectKotlinClass:
kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.ReflectKotlinClass

当 @Document 注释类被移除时,应用程序启动时没有问题。

从错误消息看来,MongoDataAutoConfiguration 需要 ReflectKotlinClass,它在类路径中找不到。 kotlin-reflect 模块在依赖列表中。是否需要任何其他 kotlin 模块?

【问题讨论】:

你能发布你的完整依赖列表吗? 【参考方案1】:

似乎提交了一份错误报告,解决了同样的问题:https://jira.spring.io/browse/DATACMNS-1245 使用 spring-data-commons 2.0.3.RELEASE 不再出现问题。

【讨论】:

以上是关于在带有 MongoDB 的 Spring Boot M7 中找不到 ReflectKotlinClass的主要内容,如果未能解决你的问题,请参考以下文章

带有反应式 mongodb 的 Spring Boot 不断尝试连接到 localhost

大写的mongoDB spring-boot自定义查询,带有LIKE

Spring Batch 使用带有 Spring Boot 的 MongoDB 抛出无法确定数据库类型的嵌入式数据库驱动程序类 NONE

无法在 Spring Boot 应用程序中连接到 MongoDB

带有 MongoTemplate 的 Spring Boot

Spring boot Embedded MongoDb 数据预填充