简体   繁体   中英

How to configure SSL mongodb connection in YML file spring boot?

I was trying to setup a ssl mongodb connection from spring boot but I couldn't able to find a way to set a connection from YML file(beacuse it's easy to maintain dev and prod environment). How can I add client.PEM and rootCA.pem keys to below connection?

Please note this not a database administration question!

data:
     mongodb:
         authentication-database: admin
         database: <database>
         host: <host>
         password: <password>
         port: <port>
         username: <username>

One way to resolve it is simple use URI string connect and database name in your application.yml file. Example:

data:  
    mongodb:  
      database: &ltdatabaseName>  
      uri: &ltmongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]>

Example with SSL option:
mongodb://user:password@mongoServer:27017/?ssl=true

More info here https://docs.mongodb.com/manual/reference/connection-string/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM