spring mvc:注解驱动未绑定

nhhxz33t  于 2022-12-10  发布在  Spring
关注(0)|答案(8)|浏览(170)

I get this error when I run a certain Spring Web 3 project in NetBeans:
org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 30; The prefix "mvc" for element "mvc:annotation-driven" is not bound.
Here's dispatcher-servlet.xml :

<?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>

I think I did the appropriate namespace declarations, but obviously I'm still overlooking something. Why am I getting this error?

ef1yzkbh

ef1yzkbh1#

这是一个IDE错误,可以通过执行以下操作解决
xmlns:mvc=”http://www.springframework.org/schema/mvc“(中文)

p4rjhz4m

p4rjhz4m2#

试试这个对我很有效:

<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 />
evrscar2

evrscar23#

它应该是这样工作的,而且它对我很有效。问题可能出在IDE / xml编辑器中。请尝试忽略xml错误并运行应用程序。

3htmauhk

3htmauhk4#

这是一个IDE错误,可以通过将以下内容添加到Spring Dispatcher Servlet中来解决
xmlns:mvc=”http://www.springframework.org/schema/mvc“(中文)
如果xml文件中不包含以下代码段,请添加它。
您http://www.springframework.org/schema/mvc。

zbdgwd5y

zbdgwd5y5#

Changing below code worked for me

<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">

to below code (imp : check xmlns:context and xmlns:xsi position)

<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">
ig9co6j1

ig9co6j16#

您可能遗漏了命名空间宣告的某个重要部分,如下所述:http://forum.springsource.org/showthread.php?100397-The-prefix-mvc-for-element-mvc-annotation-driven-is-notbound
它不会影响运行时,但是开发环境会遇到与您所描述的类似的问题。
我猜应该是这样的:http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

irlmq6kh

irlmq6kh7#

添加:xmlns:p=”http://www.springframework.org/schema/p“
否则xml将无法理解p注解。

w6lpcovy

w6lpcovy8#

我也遇到了同样的问题,于是我补充道:http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd到xsi:schemaLocation下面是我的bean标记:

<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/mvc 
       http://www.springframework.org/schema/mvc/spring-mvc-3.0.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">

相关问题