【问题标题】:Spring Rest Service - Error with 'mvc:annotation-driven'Spring Rest 服务 - 'mvc:annotation-driven' 错误
【发布时间】:2017-05-15 18:43:19
【问题描述】:

我尝试将 rest 服务集成到我现有的 spring mvc 3.0 项目中,但遇到以下错误(也尝试删除 xsd 版本)。请帮忙。

"cvc-complex-type.2.4.c: 匹配通配符是严格的,但是找不到元素'mvc:annotation-driven'的声明

这是我的 Spring 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.xsd    
        http://www.springframework.org/schema/mvc/spring-mvc  
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
        http://www.springframework.org/schema/aop  
            http://www.springframework.org/schema/mvc/spring-aop.xsd    
         http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx.xsd 
         http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context.xsd">



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

    <!--   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">      
        <property name="prefix" value="/jsp/" />
        <property name="suffix" value=".jsp" />         
    </bean> 
            --> 



    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
        <property name="basenames">
            <list>
                <value>/WEB-INF/springMessages</value>  
            </list>
        </property>
    </bean>





    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
     <property name="mediaTypes">
       <map>
   <entry key="html" value="text/html"></entry>
   <entry key="json" value="application/json"></entry>
   <entry key="xml" value="application/xml"></entry>
 </map>
     </property>
     <property name="viewResolvers">
 <list>
  <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView">
            </property>
     <property name="prefix" value="/jsp/"></property>
     <property name="suffix" value=".jsp"></property>
   </bean>
 </list>
     </property>
  </bean> 



</beans>

【问题讨论】:

    标签: java spring rest spring-mvc annotations


    【解决方案1】:

    由于您无法从我给出的第一个答案中找出错误,只需将您的 xsi:schemaLocation 替换为此

    xsi:schemaLocation="http://www.springframework.org/schema/beans  
            http://www.springframework.org/schema/beans/spring-beans.xsd    
        http://www.springframework.org/schema/mvc  
            http://www.springframework.org/schema/mvc/spring-mvc.xsd 
        http://www.springframework.org/schema/aop  
            http://www.springframework.org/schema/aop/spring-aop.xsd    
         http://www.springframework.org/schema/tx 
            http://www.springframework.org/schema/tx/spring-tx.xsd 
         http://www.springframework.org/schema/context  
            http://www.springframework.org/schema/context/spring-context.xsd"
    

    【讨论】:

      【解决方案2】:

      您的 schemaLocation 声明不正确。

      代替

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

      使用

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

      【讨论】:

      【解决方案3】:

      您的 aop xsd 位置错误。请改正。应该是

      http://www.springframework.org/schema/aop/spring-aop.xsd
      

      不是

      http://www.springframework.org/schema/mvc/spring-aop.xsd
      

      那么 mvc xsi:schemaLocation 应该是

      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
      

      不是

      http://www.springframework.org/schema/mvc/spring-mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"
      

      希望对你有帮助

      【讨论】:

      猜你喜欢
      • 2012-05-01
      • 1970-01-01
      • 2018-02-15
      • 2012-07-29
      • 2012-02-19
      • 1970-01-01
      • 2012-11-29
      • 2015-05-05
      • 1970-01-01
      相关资源
      最近更新 更多