我在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
我在文档上发现:
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。