我在使用Spring Tool Suite的servlet-context.xml中出现以下错误:
元素bean bean的前缀bean未绑定错误在以下行:http://www.springframework.org/schema/beans/spring-beans-3.0.xsd“>
顺便说一句,我正在尝试使用以下配置将Spring连接到MongoDB:
<?xml version="1.0" encoding="UTF-8"?>
<beans:bean xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<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.etvld.mvc" />
<mongo:mongo host="192.168.1.19" port="27017"/>
</beans:beans>
2 回答
您的开始和结束标记不匹配,您忘了定义
beans
名称空间:所以,用以下代替第一行:
另外,将
mvc
名称空间添加为默认名称空间:你的
servlet-context.xml
最终看起来像这样:如果您发现自己使用Spring配置会感到不舒服,我猜你会这样做,最好切换到 Spring Boot ,它会自动完成大部分这类配置 .
这是一个简单的mongo配置
它使用注释,但它与你只是@Autowire mongoTemplate相同 .
转换为xml,这看起来与此类似或相等
没有在xml上测试过,所以我可能会遗漏一些东西,
哦,正如另一个答案所指出的那样,你应该
<beans:bean .....
它应该是<beans:bean .....
并且恰当地关闭</beans:bean>
希望能帮助到你