Spring mvc:注释驱动未绑定
当我在NetBeans中运行某个Spring Web 3项目时,我遇到了这个错误: org.xml.sax.SAXParseException; 行号:11;栏目号:30;这个 元素的前缀“mvc” “mvc:注释驱动”未绑定 下面是DispatcherServlet.xml:Spring mvc:注释驱动未绑定,spring,Spring,当我在NetBeans中运行某个Spring Web 3项目时,我遇到了这个错误: org.xml.sax.SAXParseException; 行号:11;栏目号:30;这个 元素的前缀“mvc” “mvc:注释驱动”未绑定 下面是DispatcherServlet.xml: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
<?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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="net.myproject.controllers"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
我认为我做了适当的名称空间声明,但显然我仍然忽略了一些东西。为什么我会出现这个错误?它应该是这样工作的,对我来说也是这样。问题可能在IDE/xml编辑器中。尝试忽略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.mkyong.common.controller" />
<mvc:annotation-driven />
这是一个IDE错误,可以通过以下方法解决: xmlns:mvc=”http://www.springframework.org/schema/mvc" 添加: xmlns:p=”http://www.springframework.org/schema/p"
否则xml将无法理解p注释 这是一个IDE错误,可以通过向Spring Dispatcher Servlet添加以下内容来解决 xmlns:mvc=”http://www.springframework.org/schema/mvc" 如果xml文件中没有包含以下代码段,还可以添加它 xsi:schemaLocation=”http://www.springframework.org/schema/mvc
“更改下面的代码对我很有用
<beans 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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
到下面的代码(imp:check xmlns:context和xmlns:xsi位置)
应用程序不会崩溃,但经验告诉我永远不要忽视警告。你是说它可能是NetBeans或Ant bug?是的。很有可能。我刚刚在eclipse中保存了您的DispatcherServlet,它保存时没有问题。您能详细说明您的答案吗?不描述问题的解决方案。简直太棒了。。对我的代码来说,它就像一个符咒。非常感谢您的帮助。对我来说,我必须先删除这一行,然后再添加它,直到有帮助为止,即使是4年后;-)关于InteliJ IDEAWell的问题,现在已经是2020年了,而且非常清楚,“未绑定”实际上意味着没有提供有效的名称空间来解决应该做什么。一旦我添加了如上所述的mvc xml名称空间,所有问题都解决了。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">