title: How to create and config an inner builder class with spring
body: <p>I am trying to springify the following code snippet:</p>
  
  <pre><code>MongoClient mongoClient = new MongoClient("127.0.0.1", 27017);
  DB db = mongoClient.getDB("jcr");
  DocumentNodeStore ns = new DocumentMK.Builder().setMongoDB(db)
                  .getNodeStore();
  Repository repo = new Jcr(new Oak(ns)).createRepository();
  </code></pre>
  
  <p>taken from Oak website : <a href="http://jackrabbit.apache.org/oak/docs/construct.html" rel="nofollow">http://jackrabbit.apache.org/oak/docs/construct.html</a></p>
  
  <p>The problem line is:</p>
  
  <pre><code>DocumentNodeStore ns = new DocumentMK.Builder().setMongoDB(db)
                  .getNodeStore();
  </code></pre>
  
  <p>Here is how I have configured it within the xml:</p>
  
  <pre><code>&lt;bean id="builder" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK$Builder"&gt;   
          &lt;/bean&gt;
  
  &lt;bean factory-bean="builder" factory-method="setMongoDB" &gt;
         &lt;constructor-arg name="db" value="#{mongoDbTags.getDb()}"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>I have configured a <code>SimpleMongoDbFactory</code> and obtaining the db to be injected into the builder bean calling the setMethod via factory method.</p>
  
  <p>Please note this does not exist as an attribute under the builder Class but the method does exist.</p>
  
  <p>here is my config file:</p>
  
  <pre><code>    &lt;bean id="mongo" class="com.mongodb.MongoClient"&gt;
          &lt;constructor-arg name="host" value="localhost" /&gt;
          &lt;constructor-arg name="port" value="27017" /&gt;
      &lt;/bean&gt;
          &lt;bean id="mongoDbTags" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"&gt;
              &lt;constructor-arg name="mongo" ref="mongo" /&gt;
              &lt;constructor-arg name="databaseName" value="jcr111" /&gt;
          &lt;/bean&gt;
      &lt;bean id="builder" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK$Builder"&gt;   
      &lt;/bean&gt;
  
          &lt;bean factory-bean="builder" factory-method="setMongoDB" &gt;
               &lt;constructor-arg name="db" value="#{mongoDbTags.getDb()}"/&gt;
            &lt;/bean&gt;
      &lt;bean id="documentMK" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK"&gt;
      &lt;constructor-arg name="builder" ref="builder" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="oak" class="org.apache.jackrabbit.oak.Oak"&gt;
          &lt;constructor-arg name="store" value="#{builder.getNodeStore()}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jcr" class="org.apache.jackrabbit.oak.jcr.Jcr"&gt;
          &lt;constructor-arg name="oak" ref="oak" /&gt;
      &lt;/bean&gt;
          &lt;bean id="jcrSessionFactory"
              class="org.springframework.extensions.jcr.JcrSessionFactory"&gt;
              &lt;property name="repository"  value="#{jcr.createRepository()}" /&gt;
              &lt;property name="credentials"&gt;
    &lt;bean class="javax.jcr.SimpleCredentials"&gt;
                      &lt;constructor-arg index="0" value="admin" /&gt;
                      &lt;constructor-arg index="1" value="admin" /&gt;
                  &lt;/bean&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="jcrTemplate" class="org.springframework.extensions.jcr.JcrTemplate"&gt;
              &lt;property name="sessionFactory" ref="jcrSessionFactory" /&gt;
              &lt;property name="allowCreate" value="true" /&gt;
          &lt;/bean&gt;
  </code></pre>