我正在尝试使以下代码片段弹跳:

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();


取自Oak网站: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的db注入到生成器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>

最佳答案

对于其他陷入其中的人,我只是创建了一个包装器类,该包装器类从其构造函数中调用了构建器

关于java - 如何使用Spring创建和配置内部构建器类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29425258/

10-10 14:30