title: MongoDB database creation with spring data
body: <p>I am creating a sample web application with spring 3.0 and mongoDB. Following is my root-context.xml file.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
      &lt;!-- Root Context: defines shared resources visible to all other web components --&gt;
      &lt;import resource="classpath:mongo-config.xml"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>and my mongo-config.xml file is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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:c="http://www.springframework.org/schema/c"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:mongo="http://www.springframework.org/schema/data/mongo"
          xmlns:util="http://www.springframework.org/schema/util"
          xsi:schemaLocation="
              http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.1.xsd
              http://www.springframework.org/schema/data/mongo
              http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
              http://www.springframework.org/schema/util 
              http://www.springframework.org/schema/util/spring-util-3.1.xsd"&gt;
  
      &lt;!-- Default bean name is 'mongo'. write concern set to SAFE to ensure unique indexes --&gt;
      &lt;mongo:mongo host="localhost" port="27017" write-concern="SAFE"/&gt;
  
      &lt;mongo:repositories base-package="com.dashboard.repositories" /&gt;
  
      &lt;bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"&gt;
          &lt;constructor-arg name="mongo" ref="mongo"/&gt;
          &lt;constructor-arg name="databaseName" value="DASHBOARD"/&gt;
          &lt;constructor-arg name="credentials" ref="userCredentials"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;constructor-arg name="mongoDbFactory" ref="mongoDbFactory"/&gt;
          &lt;property name="writeResultChecking"&gt;
              &lt;util:constant static-field="org.springframework.data.mongodb.core.WriteResultChecking.EXCEPTION" &gt;&lt;/util:constant&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials"&gt;
          &lt;constructor-arg name="username" value="test"/&gt;
          &lt;constructor-arg name="password" value="abc123"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>when i start the tomcat server, there is no database "Dashboard" created. What is wrong with this code, Kindly help me. Thanks in advance.</p>