我们的项目用到了spring框架和mongdb数据库,随着mongodb升级到3.0已有半年时间,我们也开始随之升级,但是3.0的用户验证有所更改,导致原来的很多配置无法再用。
经过几天的尝试后,终于成功的用spring配置验证。
升级用了两个新的jar包,分别是pring-data-mongodb1.7.2(http://pan.baidu.com/s/1bnkAA67)和mongodb-java-driver3.0.2(http://pan.baidu.com/s/1jG6bc3c);
spring中的验证配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">
<mongo:mongo-client host="192.168.0.213" port="27017" credentials="admin:admin@admin" id="mongo"> <mongo:client-options write-concern="SAFE"/> </mongo:mongo-client> <mongo:db-factory id="mongoDbFactory" dbname="admin" mongo-ref="mongo" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" /> </bean> </beans>