4

これは Mongo ドライバーのバグですか、それとも間違ったことをしていますか?

例外を下回る:

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.mongodb.ServerAddress[]' for property 'replicaSetSeeds'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.mongodb.ServerAddress] for property 'replicaSetSeeds[0]': no matching editors or conversion strategy found
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:465)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:496)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:490)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1437)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
    ... 14 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.mongodb.ServerAddress] for property 'replicaSetSeeds[0]': no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:264)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:128)
    at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:487)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:195)
    at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:450)
    ... 20 more

以下は私の春の設定です

 <bean id="defaultMongoTypeMapper"  class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
    <constructor-arg name="typeKey"><null/></constructor-arg>
 </bean>

 <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    <constructor-arg name="mappingContext" ref="mappingContext" />
    <property name="typeMapper" ref="defaultMongoTypeMapper" />
 </bean>

 <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    <constructor-arg name="mongoConverter" ref="mappingMongoConverter" />   
    <property name="writeConcern">
        <util:constant static-field="com.mongodb.WriteConcern.SAFE" ></util:constant>
    </property>
 </bean>

使用されるjar/ドライバー:
spring-beans-3.2.0.RELEASE.jar mongo-java-driver-2.11.3.jar

以下のコードを使用して修正しました。

<bean id="mongoClient" class="com.mongodb.MongoClient">
    <constructor-arg>
        <list>
            <value>161.141.16.100:27017</value>
            <value>161.141.16.101:27017</value>
        </list>
    </constructor-arg>
</bean>

<mongo:db-factory id="mongoDbFactory" dbname="test" mongo-ref="mongoClient"/>
4

2 に答える 2

4

おそらく使用している

<property name="[variable]" ref="[bean]"/>

それ以外の

<property name="[variable]" value="[bean]"/>

ref は Spring Bean を参照し、値は文字列に変換されます。

于 2015-04-24T21:30:39.463 に答える