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

2022-09-03 04:05:08

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

这是我的调度程序 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>

答案 1

你有这个:

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

要解决此问题,您应该具有

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

还有,比如

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

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


答案 2

我有一个几乎与你类似的错误。我的应用程序Context.xml文件是这样的:

xsi:schemaLocation="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/beans/spring-beans.xsd">//should be context instead of beans

当我试图写作时

<context:property-placeholder location="file:src/application.properties"/>

然后我得到了错误。我通过复制下面的代码来修复错误:

xsi:schemaLocation="
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">

推荐