IAmYourFaja
IAmYourFaja

Reputation: 56912

Spring XML Configuration and Namespaces

I'm trying to configure a Spring config (xml) file and am trying to add a namespace for a valid schema file that I have living locally inside my project. The reason is that I don't have a "real" URL (web server, etc.), so I'm trying to just use a local schema that I will provide under WEB-INF/:

MyProject/
    src/
        java/
        config/
            MySchema.xsd
            spring-config.xml
    build.xml

Inside my spring-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:ms="http://myproject.org/MySchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

Project is building & deploying fine, but when I go to run it I get:

org.xml.sax.SAXException: Failed to locate XSD resource '/META-INF/MySchema.xsd' on 
classpath. Namespace: 'http://myproject.org/MySchema.xsd'.

Ultimately I'd like both spring-config.xml and MySchema.xsd stored under WEB-INF/, so I'm not sure why Spring is looking inside META-INF/... any ideas?

The URL http://myproject.org/MySchema.xsd is not a real URL, just giving the schema its own namespace. Thanks in advance!

Upvotes: 1

Views: 2353

Answers (3)

Go Dan
Go Dan

Reputation: 15502

You also need to define the schema location for your http://myproject.org/MySchema.xsd namespace. From W3C, the schema location:

consists of one or more pairs of URI references, separated by white space. The first member of each pair is a namespace name, and the second member of the pair is a hint describing where to find an appropriate schema document for that namespace. The presence of these hints does not require the processor to obtain or use the cited schema documents, and the processor is free to use other schemas obtained by any suitable means, or to use no schema at all.

I would use a different namespace name so as not to be confused with the namespace schema document hint. Maybe use a schema location such as http://myproject.org/my-schema config/MySchema.xsd instead.

Upvotes: 0

kan
kan

Reputation: 28951

Do you need define spring.schemas and spring.handlers? See more here: http://www.theserverside.com/news/1364131/Authoring-Custom-Namespaces-in-Spring-20

Upvotes: 0

DwB
DwB

Reputation: 38300

There is no "definition" (I don't know the correct term) of the http://myproject.org/MySchema.xsd in the xsi:schemaLocation attribute. Try something like this:

xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://myproject.org/MySchema.xsd location/of/MySchema.xsd">

Upvotes: 2

Related Questions