使用spring-data-mongodb的Spring bean加载错误

时间:2014-03-09 23:44:17

标签: java spring mongodb spring-data-mongodb

我们正在使用Spring版本3.2.0,现在在代码库中引入了spring-data-mongodb 1.4.0版。我尝试编写一个新的spring配置文件(mongo-config.xml),同时只定义了与mongodb相关的bean。

我的Spring配置如下:

    <?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:util="http://www.springframework.org/schema/util"
    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-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.4.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<mongo:mongoid="replicaSetMongo"replica-set="localhost:10901,localhost:10902">
<mongo:optionsconnections-per-host="8"
ssl="false" />
</mongo:mongo>

<mongo:db-factoryid="xmlLogDbFactory"
mongo-ref="replicaSetMongo"
dbname="logs"
username="logs_owner"
password="logs_owner" />

<mongo:mapping-converter>
<mongo:custom-converters>
<mongo:converter>
<beanclass="com.utils.mongodb.dao.impl.SspLogsWriteConver ter"/>
</mongo:converter>
</mongo:custom-converters>
</mongo:mapping-converter>

<beanid="xmlLogTemplate"class="org.springframework.data.mongodb.core.MongoTempla te">
<constructor-argname="mongoDbFactory"ref="xmlLogDbFactory"/>
<constructor-argname="mongoConverter"ref="mappingConverter"/>
<propertyname="writeConcern">
<util:constantstatic-field="com.mongodb.WriteConcern.UNACKNOWLEDGED"/>
</property>
</bean>

</beans>

我在JBoss上部署了应用程序。但JBoss在启动时给出的错误如下。有人可以帮我解决问题吗? 弹簧版和弹簧版之间是否存在不匹配? spring-mongodb版?我注意到异常跟踪提到了spring-beans-3.2.0 jar,即使问题是mongo-config.xml

Caused by: org.springframework.beans.factory.parsing.BeanDefi nitionParsingException: Configuration problem: Failed to import bean definitions from relative location [mongo-config.xml]
Offending resource: class path resource [spring/commonUtil-config.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Unexpected exception parsing XML document from class path resource [spring/mongo-config.xml]; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class [org.springframework.data.mongodb.config.MongoNames paceHandler] for namespace [http://www.springframework.org/schema/data/mongo]: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/config/RepositoryConfigurationExtension
at org.springframework.beans.factory.parsing.FailFast ProblemReporter.error(FailFastProblemReporter.java :68) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.parsing.ReaderCo ntext.error(ReaderContext.java:85) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.parsing.ReaderCo ntext.error(ReaderContext.java:76) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.importBeanDefinitionResour ce(DefaultBeanDefinitionDocumentReader.java:271) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.parseDefaultElement(Defaul tBeanDefinitionDocumentReader.java:196) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.parseBeanDefinitions(Defau ltBeanDefinitionDocumentReader.java:181) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.doRegisterBeanDefinitions( DefaultBeanDefinitionDocumentReader.java:140) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.registerBeanDefinitions(De faultBeanDefinitionDocumentReader.java:111) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.registerBeanDefinitions(XmlBeanDefinit ionReader.java:493) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.doLoadBeanDefinitions(XmlBeanDefinitio nReader.java:390) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:334) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:302) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.beans.factory.xml.DefaultBeanD efinitionDocumentReader.importBeanDefinitionResour ce(DefaultBeanDefinitionDocumentReader.java:255) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]
... 36 more

1 个答案:

答案 0 :(得分:0)

此问题现已解决。我意识到,当maven下载spring-data-mongodb 1.4版jar时,我的存储库中又下载了一个jar:spring-data-commons 1.7版。

我将第二个jar复制到我的WEB-INF / lib文件夹,应用程序开始工作。