在MongoDB的spring-data中配置GridFS模板

时间:2014-06-02 05:44:38

标签: java spring mongodb spring-data spring-data-mongodb

我在我的spring应用程序中配置MongoDB时遇到了麻烦(我使用Spring Data for mongo db)。以下是负责mongodb的配置部分

<mongo:mongo host="localhost" port="27017"/>
<mongo:db-factory id="mongoDbFactory" dbname="yourdb" />

<mongo:mapping-converter id="converter" />

<bean name="gridFsTemplate" class="org.springframework.data.mongodb.gridfs.GridFsTemplate">
    <constructor-arg ref="mongoDbFactory" />
    <constructor-arg ref="converter" />
</bean>

当我开始申请时,我得到以下日志:

  

引起:org.springframework.beans.factory.BeanCreationException:   使用名称&#39;转换器&#39;创建bean时出错:bean的实例化   失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:不能   实例化bean类   [org.springframework.data.mongodb.core.convert.MappingMongoConverter]:   构造函数抛出异常;嵌套异常是   java.lang.NoSuchMethodError:   org.springframework.data.util.ClassTypeInformation.from(Ljava /郎/类;)Lorg / springframework的/数据/ util的/ TypeInformation;     在   org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:304)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] ... 93个常见帧   省略引起:   org.springframework.beans.BeanInstantiationException:不能   实例化bean类   [org.springframework.data.mongodb.core.convert.MappingMongoConverter]:   构造函数抛出异常;嵌套异常是   java.lang.NoSuchMethodError:   org.springframework.data.util.ClassTypeInformation.from(Ljava /郎/类;)Lorg / springframework的/数据/ util的/ TypeInformation;     在   org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:125)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] at   org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:270)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] ... 102个常见帧   省略:java.lang.NoSuchMethodError:   org.springframework.data.util.ClassTypeInformation.from(Ljava /郎/类;)Lorg / springframework的/数据/ util的/ TypeInformation;     在   org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper。(DefaultMongoTypeMapper.java:49)   〜[spring-data-mongodb-1.4.2.RELEASE.jar:na] at   org.springframework.data.mongodb.core.convert.MappingMongoConverter。(MappingMongoConverter.java:110)   〜[spring-data-mongodb-1.4.2.RELEASE.jar:na] at   org.springframework.data.mongodb.core.convert.MappingMongoConverter。(MappingMongoConverter.java:126)   〜[spring-data-mongodb-1.4.2.RELEASE.jar:na] at   sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)   〜[na:1.8.0_05] at   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)   〜[na:1.8.0_05] at   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)   〜[na:1.8.0_05] at   java.lang.reflect.Constructor.newInstance(Constructor.java:408)   〜[na:1.8.0_05] at   org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)   〜[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE] ... 104个常见帧   省略

我认为我应该添加&#39; type-mapper-ref&#39;转换为&#39;豆,但我不知道我应该提供什么价值。

此示例的配置几乎相似:http://www.mkyong.com/mongodb/spring-data-mongodb-save-binary-file-gridfs-example/

也许你们中有些对mongodb更熟悉的人可以给我答案吗?

1 个答案:

答案 0 :(得分:1)

更改版本的spring-data-mongodb来自&#39; 1.5.0.RC&#39;到&#39; 1.5.0.RELEASE&#39;以及来自&#39; 1.8.0.RC1&#39;的spring-data-commons的版本到&#39; 1.8.0.RELEASE&#39;它解决了这个问题。可能api被改变了,并且“NoSuchMethodError”#39;不再出现了。