org.springframework.beans.factory.BeanCreationException: Error
creating bean with name ‘mongoUtils’: Invocation of init method
failed; nested exception is
org.springframework.data.mongodb.UncategorizedMongoDbException:
Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1,
userName=‘Devuser’, source=‘doc-server’, password=,
mechanismProperties=}; nested exception is
com.mongodb.MongoSecurityException: Exception authenticating
MongoCredential{mechanism=SCRAM-SHA-1, userName=‘Devuser’,
source=‘doc-server’, password=, mechanismProperties=}
- 这里可以看出是权限问题,这跟mongo的特性有关,我们需要指定这一次的权限例如:
spring.data.mongodb.uri=${MONGO_URI:mongodb://user:pwd@127.0.0.1:27017/dbname}?authSource=admin&authMechanism=SCRAM-SHA-1