2011-05-14 17 views
20

consigo este error al ejecutar un determinado proyecto de 3 Spring Web en NetBeans:MVC: anotación impulsada no está obligado

org.xml.sax.SAXParseException; lineNumber: 11; columnNumber: 30; El prefijo "mvc" para el elemento de "mvc: anotación impulsada" no está vinculado.

Aquí es 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> 

creo que hice las declaraciones de espacios adecuados, pero es evidente que todavía estoy pasando por alto algo. ¿Por qué recibo este error?

Respuesta

11

debería funcionar de esa manera, y funciona para mí. El problema podría estar en tu editor IDE/xml. Intenta ignorar el error xml y ejecuta la aplicación.

+0

la aplicación no se cae o cualquier cosa, pero la experiencia me ha enseñado a nunca ignorar las advertencias. ¿Entonces estás diciendo que podría ser un error de NetBeans o Ant? – Pieter

+0

sí. Más probable. Acabo de guardar su servlet despachador en eclipse y se guarda sin problemas. – Bozho

1

Usted probablemente está perdiendo una parte importante de la declaración de espacio de nombres, como se discute aquí: http://forum.springsource.org/showthread.php?100397-The-prefix-mvc-for-element-mvc-annotation-driven-is-notbound

No afecta el tiempo de ejecución, pero el entorno de desarrollo van a sufrir con problemas similares a los que usted describe.

supongo que debe ir de esta manera: http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

+0

¿Puede elaborar su respuesta? no describiendo la solución al problema. –

24

probar esto funcionó para mí:

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

32

esto es un error IDE, que puede ser resuelto siguiendo a

xmlns: mvc = "http://www.springframework.org/schema/mvc"

enter image description here

+0

Simplemente excelente ... Funcionó como un encanto para mi código. Muchas gracias por la ayuda. –

+0

¡Esta es una solución de trabajo para seguro! –

1

Añadir: xmlns: p = "http://www.springframework.org/schema/p"

De lo contrario XML no entender la p anotación.

2

esto es un error IDE, que puede ser resuelto mediante la adición de lo siguiente para su primavera Dispatcher Servlet

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

y también añadir el siguiente fragmento si no se incluye en el archivo XML

xsi: schemaLocation = "http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

Cuestiones relacionadas