springboot之mongoDB项目Exception in monitor thread while connecting to server localhost:27017

时间:2024-03-23 11:48:58

今天做好项目在自己电脑上测试均正常,但是部署到服务器上总是报springboot之mongoDB项目Exception in monitor thread while connecting to server localhost:27017

查看上面内容发现我的数据库明明已经链接成功了

springboot之mongoDB项目Exception in monitor thread while connecting to server localhost:27017

想了想 是数据库配置链接了2次,因为我自己写了mongoDB的链接bean,而springboot又自动配置了一遍,而报错的是springboot自己配置的。

解决办法:

1、@SpringBootApplication(exclude = {MongoAutoConfiguration.class, MongoDataAutoConfiguration.class})

2、移除<!-<dependency> <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-mongodb</artifactId> 
</dependency> 

    换成:<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.4.2</version>
</dependency>