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>

posted on 2017-01-20 18:02  白衣胜雪  阅读(119)  评论(0编辑  收藏  举报