aucune déclaration ne peut être trouvé pour l'élément 'mvc:annotation-driven"

J'ai l'obligation de retour JSON/XML des données à partir de mon contrôleur.De ce que j'ai trouvé,j'avais besoin d' @ResponseBody dans ma méthode et pour cela j'ai besoin <mvc:annotation-driven> activé. J'ai essayé toutes sortes de RnD, mais je suis toujours bloqué! 🙁

Apparemment, mon problème est dans mon servlet.xml fichier (le schéma n'est pas d'arriver validé!)
Je suis à l'aide de Printemps 3.1.1 & ont explicitement mis en spring-mvc-3.1.1.jar dans mon classpath.

Voici ma servlet-fichier de contexte sample-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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/tx                      http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/mvc-3.1  http://www.springframework.org/schema/mvc/spring-mvc-3.1.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">


  <context:component-scan base-package="com.sample.controller"/>
  <mvc:annotation-driven/>  

  <!--Use JAXB OXM marshaller to marshall/unmarshall following class-->
  <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

  <bean id="xmlViewer" 
        class="org.springframework.web.servlet.view.xml.MarshallingView">
    <constructor-arg>
      <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
          <list>
            <value>com.sample.model.SampleClass</value>
          </list>
        </property>
      </bean>
    </constructor-arg>
  </bean>

  <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">

  <property name="viewResolvers">
    <list>
      <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
    </list>
  </property>
</bean> 

Mon contrôleur de classe ressemble à ceci :

@Controller
public class XmlController {

  @RequestMapping(value="/getXml",method = RequestMethod.POST)
  public @ResponseBody AssociateDetail getXml(){
    System.out.println("inside xml controller.....");
    AssociateDetail assoBean=null;

    try{
      AssociateService add=new AssociateService();
      assoBean=add.selectAssociateBean();
    }catch(Exception e){
      e.printStackTrace();
    }

    return assoBean;    
  }
}

Maintenant, le problème est <mvc:annotation-driven /> donne une erreur:

cvc-complexe-type.2.4.c: La mise en correspondance générique est stricte, mais aucune déclaration ne peut être trouvé pour l'élément 'mvc:annotation-driven".

Et j'ai essayé toutes les solutions proposées sur ce site et au-delà. Avoir mis à jour mon schéma des espaces de noms, à l'aide de Printemps 3.1.1 et @ResponseBody.

InformationsquelleAutor user2164016 | 2013-03-14