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/
112021-12-16 -
Tendernesz
2021-07-01
更换驱动
00 -
风间影月
2021-03-05
看着像是mongodb的相关jar没有下载好,你看看删除本地的,重新下载试试看呢
052022-01-06
相似问题