找不到 Spring Boot Mongo Reactive 类 - 找不到类 [org.springframework.data.mongodb.MongoDatabaseFactory]
Posted
技术标签:
【中文标题】找不到 Spring Boot Mongo Reactive 类 - 找不到类 [org.springframework.data.mongodb.MongoDatabaseFactory]【英文标题】:Spring Boot Mongo Reactive class not found - Could not find class [org.springframework.data.mongodb.MongoDatabaseFactory] 【发布时间】:2020-11-24 15:11:52 【问题描述】:之前在 Spring boot 2.2.7 中使用 Mongo DB 反应式 - 项目运行良好
pom.xml 提取
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
</dependency>
...
</dependencies>
但在更新到 2.3.x 后,我开始出现错误。
java.lang.IllegalArgumentException: Could not find class [org.springframework.data.mongodb.MongoDatabaseFactory]
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:335)
at org.springframework.core.annotation.TypeMappedAnnotation.adapt(TypeMappedAnnotation.java:446)
at org.springframework.core.annotation.TypeMappedAnnotation.getValue(TypeMappedAnnotation.java:369)
at org.springframework.core.annotation.TypeMappedAnnotation.asMap(TypeMappedAnnotation.java:284)
at org.springframework.core.annotation.AbstractMergedAnnotation.asAnnotationAttributes(AbstractMergedAnnotation.java:193)
at org.springframework.core.type.AnnotatedTypeMetadata.getAnnotationAttributes(AnnotatedTypeMetadata.java:106)
at org.springframework.context.annotation.AnnotationConfigUtils.attributesFor(AnnotationConfigUtils.java:285)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:102)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:81)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.registerBeanDefinitionForImportedConfigurationClass(ConfigurationClassBeanDefinitionReader.java:160)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:120)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:236)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:280)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:96)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:62)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.cloudbuzz.apis.ApisApplication.main(ApisApplication.java:32)
Caused by: java.lang.ClassNotFoundException: org.springframework.data.mongodb.MongoDatabaseFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:285)
at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:325)
... 25 common frames omitted
最近有什么大的改变吗?
它仍在使用 2.2.7 和 2.2.9,但 2.3.x 给出了运行时问题,因为找不到类。
改变了哪些依赖关系?很难弄清楚,任何帮助将不胜感激
尝试了所有的mvn clean install
,从 intellij 清除缓存等
【问题讨论】:
你需要发布你所有的 pom.xml,才能知道发生了什么变化。 没有其他改变..只有版本<version>2.3.2.RELEASE</version>
甚至没有更改代码
你尝试了哪些事情......?你运行 mvn clean install 了吗?
一切都试过了,mvn clean install,从intellij清理缓存等等
【参考方案1】:
使用以下最新版本的依赖项之一。这为我解决了问题。
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
编辑:如果需要也可以
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelace-SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
【讨论】:
以上是关于找不到 Spring Boot Mongo Reactive 类 - 找不到类 [org.springframework.data.mongodb.MongoDatabaseFactory]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Spring Boot 中将 mongo db update 运算符应用为 $inc