Spring使用用户名和密码连接到mongodb

问题描述 投票:0回答:1

我在docker上运行了mongo DB。要设置用户名和密码,我设置了MONGO_INITDB_DATABASE,MONGO_INITDB_ROOT_USERNAME和MONGO_INITDB_ROOT_PASSWORD变量。

现在在Spring Boot应用程序中,可以使用URI:mongodb://username:password@host:27017/db_name?authSource=admin,它正在工作。

现在我想要更改属性,它看起来像:

spring:
  data:
    mongodb:
      authentication-database: admin
      host: host
      database: db_name
      password: password
      port: 27107
      username: username

任何想法有什么问题吗?

springboot:2.2.5spring-boot-starter-data-mongodb-active

java spring mongodb spring-boot
1个回答
0
投票

我在文档上发现:

If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration. 

所以可能是问题所在,现在我只使用URI。

© www.soinside.com 2019 - 2024. All rights reserved.