gpt4 book ai didi

java - 在 spring-data 中为 MongoDB 配置 GridFS 模板

转载 作者:太空宇宙 更新时间:2023-11-04 06:46:00 25 4
gpt4 key购买 nike

我在 Spring 应用程序中配置 MongoDB 时遇到问题(我使用 Spring Data 作为 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>

当我启动应用程序时,我收到以下日志:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'converter': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation; at 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 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.convert.MappingMongoConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation; at 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 common frames omitted Caused by: java.lang.NoSuchMethodError: org.springframework.data.util.ClassTypeInformation.from(Ljava/lang/Class;)Lorg/springframework/data/util/TypeInformation; at 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(Native Method) ~[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 common frames omitted

我认为我应该将“type-mapper-ref”添加到“converted”bean,但我不知道应该提供什么值。

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

也许你们中比较熟悉mongodb的人可以给我答案?

最佳答案

将 spring-data-mongodb 的版本从“1.5.0.RC”更改为“1.5.0.RELEASE”,将 spring-data-commons 的版本从“1.8.0.RC1”更改为“1.8.0.RELEASE”,并解决了问题。可能 api 已更改,并且“NoSuchMethodError”不再出现。

关于java - 在 spring-data 中为 MongoDB 配置 GridFS 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23987988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com