简体   繁体   中英

Spring MVC 3.1 - Namespace error

I have the following in my dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:beans="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc
                           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-3.1.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-3.1.xsd
                           http://www.springframework.org/schema/util
                           http://www.springframework.org/schema/util/spring-util-3.1.xsd">

The XML validation fails saying

Invalid content was found starting with element 'context:component-scan'. One of '{"http://www.springframework.org/schema/mvc":argument-resolvers, "http://www.springframework.org/ schema/mvc":return-value-handlers}' is expected.

I have checked the schemas defined in http://www.springframework.org/schema/mvc/ and everything seems to be fine. Previously I was using Spring mvc 3.0 and it did not face any problem. I have all my jar files directly in WEB-INF/lib . Any ideas?

Update

This is the line where the validation fails <context:component-scan base-package="com" /> and yes all the jars used are from Spring 3.1

Could be wrong, but looking at the schemas and the error given, are you perhaps trying to place the <context:component-scan base-package="com" /> -element within <mvc:annotation-driven> </mvc:annotation-driven> -tags or forgetting to close the <mvc:annotation-driven> -tag? Place the component-scan outside the tags or close the <mvc:annotation-driven> -tag properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM