Подтвердить что ты не робот

Mvc: аннотация не привязана

Я получаю эту ошибку при запуске определенного проекта Spring Web 3 в NetBeans:

org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 30; префикс "mvc" для элемента "mvc: annotation-driven" не привязан.

Здесь 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>

Я думаю, что я сделал соответствующие объявления пространства имен, но, очевидно, я все еще что-то пропускаю. Почему я получаю эту ошибку?

4b9b3361

Ответ 1

Он должен работать так, и он работает для меня. Проблема может быть в вашем редакторе IDE/xml. Попробуйте игнорировать xml-ошибку и запустить приложение.

Ответ 2

Это ошибка IDE, которая может быть решена с помощью

XMLNS: = MVC "http://www.springframework.org/schema/mvc"

enter image description here

Ответ 3

попробуйте, это сработало для меня:

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

Ответ 4

Это ошибка IDE, которая может быть решена путем добавления следующего в ваш Spring Servlet Servlet

XMLNS: = MVC "http://www.springframework.org/schema/mvc"

Также добавьте следующий фрагмент, если он не включен в ваш XML файл

XSI: SchemaLocation = "http://www.springframework.org/schema/mvc                    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

Ответ 5

Вероятно, вы пропустили значительную часть объявления пространства имен, как описано здесь: 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

Ответ 6

Добавить: XMLNS: р = "http://www.springframework.org/schema/p"

В противном случае xml не сможет понять аннотацию p.

Ответ 7

Изменение кода ниже работало для меня

<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: проверьте xmlns: context и 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">