MongoClient报错的问题

来源:5-15 整合SpringBoot【GridFS】

玛塔玛塔

2021-03-05

图片描述老师您好。
使用MongoClient时有上图的提示。install可以成功,运行的时候会报如下错误
Description:

Parameter 0 of method gridFSBucket in com.imooc.files.GridFSConfig required a bean of type ‘com.mongodb.MongoClient’ that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

Action:

Consider defining a bean of type ‘com.mongodb.MongoClient’ in your configuration.

Process finished with exit code 1

写回答

3回答

慕莱坞3126862

2021-05-28

花了我将近一个小时总算解决了。。。发出来帮大家避坑。

留意第一行

import com.mongodb.MongoClient;

这个是不对的!!

应该是

import com.mongodb.client.MongoClient;

同时mongoDB 3.11 的driver不支持最新的4.4版本的mongoDB,可以使用最新的:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
    <version>4.2.3</version>
</dependency>

需要修改定级pom和model的pom。

参考: https://mongodb.github.io/mongo-java-driver/4.2/driver/getting-started/installation/

1
1
爱吃奥利奥
按照如上方法,还是不能注入哎
2021-12-16
共1条回复

Tendernesz

2021-07-01

更换驱动

0
0

风间影月

2021-03-05

看着像是mongodb的相关jar没有下载好,你看看删除本地的,重新下载试试看呢

0
5
rddata
回复
爱吃奥利奥
我和你一样的问题,请问你解决了吗
2022-01-06
共5条回复

Spring Cloud 进阶 Alibaba 微服务体系自媒体实战

一课收获分布式系统开发,微服务核心技术和中间件企业生产落地

1113 学习 · 896 问题

查看课程