Integrated configuration of 1.Spring integrated MongoDB
If you are using a MAVEN project, add a package dependency.
<Dependency> <groupId>Org.springframework.data</groupId> <Artifactid>Spring-data-mongodb</Artifactid> <version>1.2.0.RELEASE</version> </Dependency>
Configuration of MongoDB in the spring configuration file
<Mongo:mongoID= "MONGO"Replica-set= "localhost:27017"> <!--number of connections per IP - <!--<mongo:options connections-per-host= "threads-allowed-to-block-for-connection-multiplier=" Connect -timeout= "Max-wait-time=" auto-connect-retry= "true" socket-keep-alive= "true" socket-timeout= "1 "slave-ok=" true "write-number=" 1 "write-timeout=" 0 "write-fsync=" true "/> - <mongo:optionsConnections-per-host= "+"Threads-allowed-to-block-for-connection-multiplier= "+"Auto-connect-retry= "true"/> </Mongo:mongo> <!--MONGO factory, through it to get MONGO instance, dbname for MongoDB database name, no words will be automatically created - <mongo:db-factorydbname= "Bimaiapp"Mongo-ref= "MONGO"/> <!--MongoDB's main operating object, all the additions and deletions to MongoDB is done through it - <BeanID= "Mongotemplate"name= "Mongotemplate"class= "Org.springframework.data.mongodb.core.MongoTemplate"> <Constructor-argname= "Mongodbfactory"ref= "Mongodbfactory"/> </Bean> <!--Map the converters, scan the files under the Back-package directory, and according to the annotations, map them as a collection of MongoDB - <Mongo:mapping-converterBase-package= "SPIDER.DTO,DB2." Pojo,spider.po " /> <!--The repository directory of the MongoDB bean, which automatically scans the interface that extends the Mongorepository interface for injection - <mongo:repositoriesBase-package= "Repository"/> <!--To translate all mongoexceptions thrown in @Repository annotated classes - <Context:annotation-config/>
2.java Package MongoDB operation-to set up in the configuration file that folder is a mapping configuration to the entity and collection of MongoDB, as
Using Mongorepository to configure the location of the Bean warehouse in the configuration file
Adopt Mongooperations method More, closer to MONGO original ecology language
Spring Integrated MongoDB and operation