Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB 3.0 connection and authentication using spring data 1.4.1.RELEASE

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>
like image 510
Archit Avatar asked May 09 '15 19:05

Archit


1 Answers

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. :-)

like image 200
Archit Avatar answered Nov 12 '22 02:11

Archit