mongdb connection with auth

below connection needs mongo-java-driver dependency

<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
<mongo:db-factory id="mongoDbFactory" client-uri="mongodb://${mongo.username}:${mongo.password}@${mongo.host}:${mongo.port}/${mongo.dbname}" />
<!-- Factory bean that creates the Mongo instance -->

<!-- MongoTemplate for connecting and quering the documents in the database -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
</bean>

原文地址:https://www.cnblogs.com/goldengallo/p/6323556.html