spring项目整合mongodb进行开发

感情迁移 提交于 2019-12-06 20:54:33

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. 编写测试代码:





易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!