- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我将请求传递给 RestController
时,出现以下错误。
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 22 in XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 108; The prefix "beans" for element "beans:bean" is not bound.
org.xml.sax.SAXParseException; lineNumber: 22; columnNumber: 108; The prefix "beans" for element "beans:bean" is not bound.
这是 Controller :
@RestController
public class smsController {
@RequestMapping(value = "/sendSMS", method = RequestMethod.POST)
public void sendMessage(@RequestBody MessageBean msgBean) throws UnsupportedEncodingException {
String numbers = msgBean.getNumbers();
String message = msgBean.getMessages();
}
}
和dispatcher-servlet xml
:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.spring.rest.controllers" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="jsonMessageConverter"/>
</beans:list>
</beans:property>
</beans:bean>
</beans>
类路径上的 jar :
jackson-annotations-2.3.2.jar
jackson-databind-2.3.2.jar
jackson-core-2.3.2.jar
我不确定是什么原因导致了这个问题。当我使用新的 jackson 2.7.4
jar 时,我收到另一个错误:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonTypeInfo$As
最佳答案
这个错误很明显,与 jackson 无关:
The prefix "beans" for element "beans:bean" is not bound.
它表示 beans
前缀或命名空间未定义。由于 beans
是默认命名空间:
xmlns="http://www.springframework.org/schema/beans"
因此,您应该从以下位置删除 beans:
前缀:
<beans:bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<beans:property name="messageConverters">
<beans:list>
<beans:ref bean="jsonMessageConverter"/>
</beans:list>
</beans:property>
</beans:bean>
最终结果如下:
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<ref bean="jsonMessageConverter"/>
<list>
</property>
</bean>
如果您打算通过此配置启用 JSON 转换,我应该说没有必要。由于对类路径存在适当的依赖关系,Spring MVC 将自动注册所需的 HttpMessageConverter 以进行 JSON 转换。 因此您可以删除该配置。
最后,您的 dispatcher-servlet.xml
将如下所示:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.spring.rest.controllers" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
还有一句建议,如果您是 Spring 框架的新手,最好从 Spring Boot 开始.
关于java - Spring框架的XmlBeanDefinitionStoreException : The prefix "beans" for element "beans:bean" is not bound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37376868/
当尝试部署我的 portlet(使用 Web 服务)时,我收到此异常: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreExce
我正在尝试以下代码:http://www.dineshonjava.com/2012/12/spring-mvc-with-hibernate-crud-example.html#.Uus0bvnoS
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在尝试在我的应用程序中实现 spring 安全性> 我正在关注此代码项目教程 http://www.codeproject.com/Articles/253901/Getting-Started-
我环顾四周,所以我还没有找到解决这个问题的解决方案。我有一个使用 Spring 的 Maven 项目,我调用 assembly-single 并构建一个可运行的 jar。该项目在 IDE 中运行良好,
我想从我的jsp访问我的资源(css,js ...)文件夹..我正在使用带有hibernate集成的spring security ....为了访问这些文件,我使用了 mvc:resources ..
本文整理了Java中org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException.()方法的一些代码示例,展示了XmlBe
本文整理了Java中org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException.getCause()方法的一些代码示例,
我使用 spring mvc 和 hibernate 开发服务器。所以,我使用 Spring mvc 和 maven 编写我的服务器程序。但是,当我在 tomcat 服务器上启动我的服务器程序时,会发
好吧,我是第一次使用 spring mvc,我不知道如何解决这个错误。我正在尝试一个简单的 mvc 程序 这是我的 web.xml 文件 FirstSpringMVCProject
org.hibernate.di
以下是错误堆栈跟踪。 SEVERE: Exception sending context initialized event to listener instance of class org.spr
我是一名优秀的程序员,十分优秀!