【发布时间】:2020-10-29 16:01:57
【问题描述】:
我想让 application.yml 在运行测试时使用和不使用用户名/密码。我的服务器需要凭据,但是当我在本地主机上时,我希望它在没有身份验证和默认设置的情况下工作。弹簧轮廓(“integrationtest”)应该保持不变。
我有以下 Spring Boot MongoDB 配置:
mongodb:
uri: mongodb://${mongodb_username:testuser}:${mongodb_password:testpassword}@${mongodb_ip:localhost}:${mongodb_port:27017}/testDB
如果我删除用户名和密码,我会收到此错误:
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='testuser', source='testDB', password=<hidden>, mechanismProperties=<hidden>}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='testuser', source='testDB', password=<hidden>, mechanismProperties=<hidden>}
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
我怎样才能使它与相同的配置文件一起工作?也许有嵌套变量的方法?谢谢。
【问题讨论】:
-
我可以将完整的 uri 放入一个变量中
标签: mongodb spring-boot