I am facing issue in connecting to mongodb 3.0 using spring data if I am using <mongo:mongo … />
tag then it is showing issue with authentication failure message when my application queries the database and if I am using <mongo:mongo-client … />
and <mongo:client-options … />
then my application gives SAX exception in my mongoDb xml config file. And one more thing I would like to mention here is we are using replica set in mongodb.
Kindly suggest some solution for this problem.
Thanks in advance.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <context:property-placeholder location="classpath:mongo.properties" /> -->
<mongo:mongo-client id="mongo" replica-set="xxx.xx.x.xx:27017,xxx.xx.x.xx::27017" credentials="admin:abc_123@xyz">
<mongo:client-options write-concern="NONE"
connections-per-host="10"
connect-timeout="30000"
max-wait-time="10000"
/>
</mongo:mongo-client>
<!-- MongoTemplate for connecting and querying the documents in the database -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="xyz"/>
</bean>
</beans>
It was my mistake mongo-client is available in spring-data-mongodb:1.7.0 and I was using 1.4.1 and after updating spring data I had to update my spring to 4 due to some unresolved dependencies. Now it is working fine. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With