繁体   English   中英

使用 xml 使用 spring mvc 配置 mongodb

[英]mongodb configuration with spring mvc using xml

我正在尝试使用 xml 文件使用 spring mvc 配置 mongodb。 我收到此错误请帮我解决此错误

抛出的异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]: Cannot resolve reference to bean 'mongoDbFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'mongoDbFactory' available

根据各种教程,这是我的 Spring 配置 XML:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:repository="http://www.springframework.org/schema/data/repository" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
          http://www.springframework.org/schema/data/mongo
          http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd">
    <annotation-driven />

    <context:property-placeholder location="classpath:mongo.properties"/>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.excelit.signup" />

    <mongo:mongo id="mongo" host="localhost" port="27017" />

    <beans:bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
    <beans:constructor-arg name="mongoDbFactory" ref="mongoDbFactory"></beans:constructor-arg>
        </beans:bean>
</beans:beans>

例外是说 mongoDBFactory 没有 bean。

尝试在 mongo 命名空间中添加工厂和客户端 bean...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM