简体   繁体   English

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

[英]Spring connect to mongodb using username and password

I've got mongo DB running on docker.我在 docker 上运行了 mongo DB。 To set username and password I set MONGO_INITDB_DATABASE, MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD variables.要设置用户名和密码,我设置了 MONGO_INITDB_DATABASE、MONGO_INITDB_ROOT_USERNAME 和 MONGO_INITDB_ROOT_PASSWORD 变量。

And now on spring boot application a can use URI: mongodb://username:password@host:27017/db_name?authSource=admin and it's working.现在在 Spring Boot 应用程序上可以使用 URI: mongodb://username:password@host:27017/db_name?authSource=admin并且它正在工作。

Now I want changed properties and it looks like:现在我想要更改属性,它看起来像:

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

Any ideas what is wrong?任何想法有什么问题?

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

I found that on the documentation:我在文档中发现:

If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported.如果您使用 Mongo 3.0 Java 驱动程序,则不支持spring.data.mongodb.hostspring.data.mongodb.port In such cases, spring.data.mongodb.uri should be used to provide all of the configuration.在这种情况下,应该使用spring.data.mongodb.uri来提供所有配置。

So probably this is the problem and for now I just stay with the URI.所以可能这就是问题所在,现在我只保留 URI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用用户名和密码连接到Java中的MongoDB 3.2? - How to connect to MongoDB 3.2 in Java with username and password? 使用JSoup通过用户名/密码连接到网站 - Using JSoup to connect to a website with username/password 使用JSch无需用户名或密码即可连接到服务器 - Connect to server without username or password using JSch Spring Security 5.2 / WebClient 使用用户名和密码连接到另一个服务的方式是什么? - What's the Spring Security 5.2 / WebClient way of using username & password to connect to another service? 在 Spring Boot 的应用程序属性中无需提供用户名和密码即可连接到 RabbitMQ - Connect to RabbitMQ without providing username and password in Application properties in Spring Boot JDBC使用密码连接但没有用户名吗? - JDBC connect with password but no username? FTP没有用户名和密码连接? - FTP connect with no username and password? OLAP4J:如何使用用户名和密码连接到多维数据集 - OLAP4J: How to connect to a Cube using username and password springboot / jpa无法使用密码“ no”连接用户名“ @localhost”的mysql? - springboot/jpa can't connect to mysql with username “@localhost” using password no? 如何使用sshj java api连接用户名和密码的远程机器? - How to connect to a remote machine with username and password using sshj java api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM