使用spring数据1.4.1.RELEASE进行MongoDB 3.0连接和身份验证

时间:2015-05-09 19:52:39

标签: java spring mongodb spring-data spring-data-mongodb

朋友您好我在使用spring数据连接到mongodb 3.0时遇到问题如果我正在使用标签,那么当我的应用程序查询数据库并且我正在使用然后我的应用程序提供SAX异常时它显示身份验证失败消息的问题我的mongoDb xml配置文件。我想在这里提到的另一件事是我们在mongodb中使用副本设置请为此问题提出一些解决方案。提前谢谢。

<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 quering 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>

1 个答案:

答案 0 :(得分:1)

我的错误mongo-client在spring-data-mongodb:1.7.0中可用,我使用的是1.4.1,在更新spring数据之后,由于一些未解决的依赖关系,我不得不将spring更新为4。现在工作正常。 : - )