spring继承Mongo使用的是spring-data.
如果需要加入两个mongo与spring集成的包,spring-data-commons-1.7.0.RELEASE.jar,spring-data-mongodb-1.4.0.RELEASE.jar。
mongo的配置
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg name="mongoDbFactory"> <bean class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"> <constructor-arg name="uri" ref="mongoURI"/> </bean> </constructor-arg> </bean> <bean id="mongoURI" class="com.mongodb.MongoURI"> <constructor-arg name="uri" value="mongodb://127.0.0.1:27017/mymongo"/> </bean> </beans>
时间: 2024-10-08 17:50:47