简体   繁体   中英

MongoDB + Spring integration

I am trying to integrate a project with Spring + MongoDB + Mongolab + JSF, I found many tutorials, but i didnt find how to configure a remote monogodb database (such as MongoLab) in the Spring Configuration XML file:

<mongo:mongo host="127.0.0.1" port="27017" />
<mongo:db-factory dbname="yourdb" />

Where can I put the login credentials? Please help

Here is the working bloc of code

    <mongo:mongo id="mongo" host="domainName" port="portNumber" />

    <mongo:db-factory id="mongoDbFactory"
              host="domainName"
              port="portNumber"
              username="userName"
              password="passWord"
              dbname="DBName"
              mongo-ref="mongo" />

     <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
         <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
     </bean>

I tried it and it is working 100%
Thank you for your help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM