1
我想springify下面的代碼片段:如何創建和配置內部生成器類與春天
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();
從橡樹網站採取:http://jackrabbit.apache.org/oak/docs/construct.html
問題行是:
DocumentNodeStore ns = new DocumentMK.Builder().setMongoDB(db)
.getNodeStore();
下面是我如何在xml中配置它:
<bean id="builder" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK$Builder">
</bean>
<bean factory-bean="builder" factory-method="setMongoDB" >
<constructor-arg name="db" value="#{mongoDbTags.getDb()}"/>
</bean>
我已經配置了一個SimpleMongoDbFactory
並獲取要注入到通過工廠方法調用setMethod的構建器bean中的數據庫。
請注意,這不作爲建造者類下的屬性存在,但該方法確實存在。
這裏是我的配置文件:
<bean id="mongo" class="com.mongodb.MongoClient">
<constructor-arg name="host" value="localhost" />
<constructor-arg name="port" value="27017" />
</bean>
<bean id="mongoDbTags" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
<constructor-arg name="mongo" ref="mongo" />
<constructor-arg name="databaseName" value="jcr111" />
</bean>
<bean id="builder" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK$Builder">
</bean>
<bean factory-bean="builder" factory-method="setMongoDB" >
<constructor-arg name="db" value="#{mongoDbTags.getDb()}"/>
</bean>
<bean id="documentMK" class="org.apache.jackrabbit.oak.plugins.document.DocumentMK">
<constructor-arg name="builder" ref="builder" />
</bean>
<bean id="oak" class="org.apache.jackrabbit.oak.Oak">
<constructor-arg name="store" value="#{builder.getNodeStore()}" />
</bean>
<bean id="jcr" class="org.apache.jackrabbit.oak.jcr.Jcr">
<constructor-arg name="oak" ref="oak" />
</bean>
<bean id="jcrSessionFactory"
class="org.springframework.extensions.jcr.JcrSessionFactory">
<property name="repository" value="#{jcr.createRepository()}" />
<property name="credentials">
<bean class="javax.jcr.SimpleCredentials">
<constructor-arg index="0" value="admin" />
<constructor-arg index="1" value="admin" />
</bean>
</property>
</bean>
<bean id="jcrTemplate" class="org.springframework.extensions.jcr.JcrTemplate">
<property name="sessionFactory" ref="jcrSessionFactory" />
<property name="allowCreate" value="true" />
</bean>