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

Abh*_*ngh 14 java spring spring-mvc spring-security

我在我的lib文件夹中添加了spring-security-config-3.1.0.RC3.jar,但仍然出现此错误.可能的原因是什么?

这是我的dispatcher-servlet.xml

<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-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

   <context:component-scan base-package="com.tcs.rspm.controller" />
<mvc:annotation-driven /> 
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="prefix" value="/webpages/" />
      <property name="suffix" value=".jsp" />
   </bean>

</beans>
Run Code Online (Sandbox Code Playgroud)

eis*_*eis 37

You have this:

xmlns:mvc="http://www.springframework.org/schema/mvc"
Run Code Online (Sandbox Code Playgroud)

but you're not mentioning it here:

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">
Run Code Online (Sandbox Code Playgroud)

To fix that, you should have

http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
Run Code Online (Sandbox Code Playgroud)

there as well, like

xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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">
Run Code Online (Sandbox Code Playgroud)

注意:模式引用实际上通常不提及Spring版本以允许更容易的升级,因此您应该使用引用http://www.springframework.org/schema/context/spring-context.xsd而不是-3.0名称中的引用.