xml - Spring Data mongodb: adding credentials for MongoDb access -


i have following working configurations in spring application:

<mongo:mongo id="myrs" replica-set="myhost:27017">    <mongo:options max-wait-time="1500"                    connect-timeout="30000" /> </mongo:mongo>  <bean id="mongotemplate" class="org.springframework.data.mongodb.core.mongotemplate">     <property name="writeresultchecking" value="exception"/>     <property name="writeconcern" value="fsync_safe"/>     <constructor-arg ref="myrs"/>     <constructor-arg name="databasename" value="mydb"/> </bean> 

now want set username/password accessing mongo database without changing code (i.e. updating spring app context xml file). possible? if so, how?

thanks.

you can pass username password mongotemplate. using propertyplaceholderconfigurer can read username , password property file.

<bean id="mongotemplate" class="org.springframework.data.mongodb.core.mongotemplate">     <property name="writeresultchecking" value="exception"/>     <property name="writeconcern" value="fsync_safe"/>     <constructor-arg ref="myrs"/>     <constructor-arg name="databasename" value="mydb"/>     <constructor-arg name="usercredentials" ref="usercredentials"/> </bean>  <bean id="usercredentials" class="org.springframework.data.authentication.usercredentials">     <constructor-arg name="username" value="username" />     <constructor-arg name="password" value="password" /> </bean> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -