我想从库中检索一些秘密(数据库用户名/密码),并使用spring.data.mongodb配置MongoDB。
我在spring-boot-starter-data-mongodb应用程序中完成了保管库集成。
硬编码的值工作正常,尝试使用${vault.application-name.property_name}
这是我在application.yml中提供的配置:
spring:
data:
mongodb:
host: 10.xx.xxx.xxx
port: 27017
database: ${vault.application-name.database-name}
username: ${vault.application-name.database-username}
password: ${vault.application-name.database-password}
authentication-database: ${vault.application-name.authentication-database}
考虑以上配置是否正确,我应该从Vault接收这些属性,但是当前,应用程序在执行时抛出以下异常:
2019-07-29 11:28:20,683 [iption='null'}-localhost:27017] org.mongodb.driver.cluster INFO Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.3.jar:?]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.3.jar:?]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) [mongodb-driver-core-3.4.3.jar:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:1.8.0_181]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_181]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_181]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_181]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_181]
at java.net.Socket.connect(Socket.java:589) ~[?:1.8.0_181]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.3.jar:?]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.3.jar:?]
... 3 more
答案 0 :(得分:0)
与Spring Cloud Vault集成时,理想情况下唯一要提供的是role
名称。
除了使用Spring Boot的Spring Cloud Vault之外,我不建议使用其他任何集成方法,因为您需要在Spring Boot初始化MongoDB配置之前获取属性,这可能会非常棘手。
有关更多参考,请参见docs,这是指向MySQL with Spring Cloud Vault示例的链接。