Java – spring. “schemaLocation … must have even number of URI’s”

javaspringspring-mvcxmlxsd

snippet from my xml file:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop" 
       xmlns:util="http://www.springframework.org/schema/util"
       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/util 
           http://www.springframework.org/schema/util/spring-util.xsd
           http://www.springframework.org/schema/context/spring-context-3.1.xsd">

<!--            http://www.springframework.org/schema/aop  -->
<!--            http://www.springframework.org/schema/aop/spring-aop.xsd"> -->

    <context:component-scan base-package="myPackage" />

after execution I see following message:

WARN [WrapperSimpleAppMain] [XmlBeanDefinitionReader] Ignored XML
validation warning org.xml.sax.SAXParseException; lineNumber: 14;
columnNumber: 80; SchemaLocation: schemaLocation value =
'http://www.springfr amework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.spri ngframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springfra mework.org/schema/context/spring-context-3.1.xsd'
must have even number of URI's.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)

How to solve this problem right?

Best Answer

Your schemaLocation value should be of the form

namespace-name schema-location [namespace-name schema-location]

You're missing

http://www.springframework.org/schema/context

before

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

It should therefore be

xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
           http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-3.1.xsd  
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.1.xsd">

Note that I've changed the util schema to version 3.1. Don't mix and match. Use all the same versions.

Related Topic