Spring Mongodb连接 [英] Spring Mongodb Connectivity
本文介绍了Spring Mongodb连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Conf.xml文件包含
<? xml version = " encoding = " < beans =" http://www.springframework.org/schema/beans"
xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance"
xmlns:cloud =" http://schema.cloudfoundry.org/spring"
xmlns:jdbc =" http://www.springframework.org/schema/jdbc"
xmlns:util =" http://www.springframework.org/schema/util"
xmlns:mongo =" http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation =" http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.7.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> ;
< bean =" mongoTemplate" 类 org.springframework .data.mongodb.core.MongoTemplate" < constructor-arg ref =" >
< /bean >
< bean mongoDbFactory" class org.springframework.data.mongodb.core.SimpleMongoDbFactory" < constructor-arg ref =" >
< constructor-arg 名称 =" 值 mydb " 类型 字符串" >
< /bean >
< bean =" mongo" 类 com.mongodb .Mongo" >
< constructor-arg 名称 =" 值 127.0 .0.1" 类型 字符串" >
< constructor-arg 名称 =" 值 27017 " 类型 int" >
< /bean >
< /beans >
我得到的错误如下
无法加载应用程序上下文
原因:org.springframework.beans.factory.BeanCreationException:在类路径资源[mongo-conf.xml]中创建名称为'mongoTemplate'的bean时出错.嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.data.mongodb.core.MongoTemplate]:构造函数抛出了异常;嵌套异常是java.lang.IllegalAccessError:尝试访问方法org.springframework.core.GenericTypeResolver.getTypeVariableMap(Ljava/lang/Class;)Ljava/util/Map;来自类org.springframework.data.util.ClassTypeInformation
解决方案
Quelle Surprise-您的配置文件"mongo-conf.xml"不正确.但是我想你已经想通了.
您是否真的提供了一个名为"mydb"的数据库?它可以在本地主机上使用吗?您能解决它(ping左右)吗?
我也有同样的问题.您对这个问题有任何解决办法吗?
我已经在春季论坛上发布了类似的问题.
http://forum. springsource.org/showthread.php?124092-spring-data-mongodb-issue-with-mongotemplate-bean-instantiation&p=404778#post404778 [<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.7.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> <constructor-arg ref="mongoDbFactory"/> </bean> <bean id ="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory"> <constructor-arg ref="mongo"/> <constructor-arg name="databaseName" value="mydb" type="String"/> </bean> <bean id="mongo" class="com.mongodb.Mongo"> <constructor-arg name="host" value="127.0.0.1" type="String"/> <constructor-arg name="port" value="27017" type="int"/> </bean> </beans>
And the Error which is I am getting is as follows
Failed to load application context
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [mongo-conf.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoTemplate]: Constructor threw exception; nested exception is java.lang.IllegalAccessError: tried to access method org.springframework.core.GenericTypeResolver.getTypeVariableMap(Ljava/lang/Class;)Ljava/util/Map; from class org.springframework.data.util.ClassTypeInformation解决方案Quelle Surprise - your config file "mongo-conf.xml" is not ok. But I guess you already figured that.
Do you really provide a DB called "mydb" ?? is it available at localhost? can you address it (ping or so)?
i have the same problem. Did you get any resolution to this problem ?
I have posted a similar question on spring forums.
http://forum.springsource.org/showthread.php?124092-spring-data-mongodb-issue-with-mongotemplate-bean-instantiation&p=404778#post404778[^]
这篇关于Spring Mongodb连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文