Spring Boot 4.0.3忽略spring.data.mongodb.uri配置,默认连接localhost:27017的问题求助
Spring Boot 4.0.3忽略spring.data.mongodb.uri配置,默认连接localhost:27017的问题求助
我正在使用Spring Boot 4.0.3和Java 21,尝试使用SRV连接字符串连接MongoDB Atlas集群。
在我的application.properties中配置了:
spring.data.mongodb.uri=mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/test?retryWrites=true&w=majority
依赖配置如下:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency>
我没有定义以下配置项:
spring.data.mongodb.host spring.data.mongodb.port
然而,当我启动应用时,日志显示:
MongoClient created with settings ... hosts=[localhost:27017] credential=null sslSettings={enabled=false}
很明显它忽略了Atlas的URI配置,默认连接到localhost了。
额外细节:
- Spring Boot版本:4.0.3
- MongoDB Java驱动:5.6.3
- 操作系统:Windows 11
- JDK:21
- 没有自定义MongoClient Bean
项目中同时配置了PostgreSQL(JPA),并且工作正常。
为什么Spring Boot会忽略spring.data.mongodb.uri配置,回退到localhost呢?
备注:内容来源于stack exchange,提问作者KRISHNA BHISE
相关产品推荐
相关产品推荐

