如何将mongo选项配置添加到spring

时间:2014-11-04 13:14:42

标签: spring-data-mongodb

我的mongo配置看起来像这样

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">

<bean id="mongo" class="com.mongodb.Mongo">
        <constructor-arg name="addr" ref="address" />
        <constructor-arg name="options" ref="options" />
    </bean>

    <bean id="options" class="com.mongodb.MongoOptions">
        <property name="connectionsPerHost" value="100"/>
        <property name="maxWaitTime" value="500"/>
    </bean>

    <bean id="address" class="com.mongodb.ServerAddress">
        <constructor-arg name="host" value="X.X.X.X" />
        <constructor-arg name="port" value="27017" />
    </bean>

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

    </bean>
...

一切运作良好!

但是 In the Mongo XSD,有一个名为“threads-allowed-to-block-for-connection-multiplier”的书面属性。当我添加这个时,我有这样一个错误:

org.springframework.beans.NotWritablePropertyException: Invalid property 'threads-allowed-to-block-for-connection-multiplier' of bean class [com.mongodb.MongoOptions]: Bean property 'threads-allowed-to-block-for-connection-multiplier' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
你知道会发生什么吗?我的新xml看起来像这样:

<bean id="options" class="com.mongodb.MongoOptions">
    <property name="connectionsPerHost" value="100"/>
    <property name="threads-allowed-to-block-for-connection-multiplier" value="5"/>
    <property name="maxWaitTime" value="500"/>
</bean>

1 个答案:

答案 0 :(得分:1)

该属性在com.mongodb.MongoOptions中命名为 threadsAllowedToBlockForConnectionMultiplier

<bean id="options" class="com.mongodb.MongoOptions">
    <property name="connectionsPerHost" value="100"/>
    <property name="threadsAllowedToBlockForConnectionMultiplier" value="5"/>
    <property name="maxWaitTime" value="500"/>
</bean>