Spring Integrated MongoDB and operation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.