spring项目整合mongodb进行开发:
MongoDB的性能指标:
100个并发,插入550万条记录的平均吞吐量:大约4100条/秒
MONGODB实际上是一个内存数据库,先将数据保存到内存,然后再写入磁盘中
1.官网下载mongodb.
https://www.mongodb.org/downloads
2.redhat上安装好mongodb
3. spring中配置mongodb:
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util" 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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/aop/spring-util.xsd
http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
<mongo:mongo host="192.168.1.104" port="27017"/>
<bean id = "mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="mymongdb"/>
<constructor-arg name="defaultCollectionName" value="xiejunbo"/>
</bean>
<bean id="person" class="com.mongo.dao.impl.PersonRepository">
<property name="mongoTemplate" ref="mongoTemplate"></property>
</bean>
<context:annotation-config />
</beans>
4. 编写测试代码:
来源:oschina
链接:https://my.oschina.net/u/1789904/blog/494153