没有声明可以找到'mvc:annotation-driven'

时间:2013-07-06 11:04:03

标签: spring model-view-controller spring-mvc

我有简单的网络应用程序(春季3 +百里香,部署在glassfish 3.x上)。当我尝试运行它时出现错误:

SEVERE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 16 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 24; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.

这是我的applicationContext.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.1.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/context/spring-mvc-3.1.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
          <context:component-scan base-package="arek" />
         <mvc:annotation-driven></mvc:annotation-driven>
   </beans>

我搜索但没有搜索。谢谢你的帮助。

2 个答案:

答案 0 :(得分:3)

尝试使用http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd代替http://www.springframework.org/schema/context/spring-mvc-3.1.xsd

希望这有帮助。

答案 1 :(得分:0)

您尝试在应用程序上下文中引用的spring MVC架构文件(http://www.springframework.org/schema/context/spring-mvc-3.1.xsd)不存在。在浏览器中自己打开此链接,您将看到404错误。最新的MVC架构文件位置是(http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd)。使用它,你不会得到例外。