First, preface
In fact, the previous project group has also used MongoDB, only then as the main database to use, so the framework will be more complex, such as the use of JPA, if only to use MongoDB as an attached database, Individuals think that the database can be manipulated by Spring-data-mongodb Mongotemple.
Two, spring integration MongoDB configuration file as follows: (User name password is missing)
<?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" xmlns:mongo= "Http://www.springframework.org/schema/data/mongo" xsi:schemalocation= "http// Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframework.org/schema/data/mongo Http://www.springframework.org/schema/data/mongo/sprin G-mongo-1.0.xsd Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/bean S/spring-beans-3.0.xsd "><mongo:mongo host=" 192.168.5.117 "port=" 27017 "/><bean id=" Mongotemplate "class = "Org.springframework.data.document.mongodb.MongoTemplate" ><constructor-arg name= "MONGO" ref= "MONGO"/> <constructor-arg name= "DatabaseName" value= "Iflashbuy-log"/><constructor-arg name= "DefauLtcollectionname "value=" Log "/></bean></beans>
Third, MAVEN configuration
As below, the key is to configure the MAVEN repository separately, because MongoDB is mostly log records, so actually do not want to map the entity, if can be done by simple entity can correspond with MONGO, In this respect, the 1.0.0.m2 version of Spring-data-mongodb can be implemented, and this version is not available in the central repository.
Iv. usage of Mongotemple
@Testpublic void Testadd () {ApplicationContext ctx = new Genericxmlapplicationcontext ("classpath*: Applicationcontext-mongo.xml "); mongooperation = (mongooperations) ctx.getbean (" Mongotemplate "); Logvo logvo = new Logvo () logvo.setusername ("15920564512"); Mongologservice.save (LOGVO); Query logquery = new query (Criteria.where ("UserName"). Is ("15920564512")); Logvo = Mongooperation.findone ("Log", LogQuery, Logvo.class); Assert.assertnotnull (LOGVO);}
Manipulating MongoDB with Spring-data-mongodb