Connecting to MongoDB 3.0 with Java Spring

后端 未结 5 1346
一向
一向 2020-12-08 08:51

I am having problems in using Spring to access MongoDB with credentials. While without credentials it works like a charme, using them just fails saying

    F         


        
5条回答
  •  情书的邮戳
    2020-12-08 09:48

    spring.data.mongodb.host and spring.data.mongodb.port are not supported if you’re using the Mongo 3.0 Java driver. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration, like this:

    spring.data.mongodb.uri=mongodb://user:secret@mongo1.example.com:12345
    

    Just add the spring.data.mongodb.uri to your application.yml and you'll get the auto configured MongoDbFactory and MongoTemplate.

提交回复
热议问题