Why it’s better to integrate XML schema files into the classpath
When using schema files in your XML configuration, it’s might happen that your XML parser will attempt to actually download the schema file using the configured schema URI.
This is the case when there is no mechanism for resolving the schema URI to a local schema file (as, for example the bean handler registration in spring) or when such a mechanism fails.
Unfortunately, the XSD URI may either not be retrieved (since not all server configurations permit HTTP connections from an application) or the XSD URI may just be an alias intended to be resolved by a mechanism such as the previously mentioned spring handlers.
In that case, it is very likely that the XML validation by the parser will fail without providing a hint to the missing XSD file that caused the failure, very likely with an error message like this:
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ...
Thus, it is recommended to provide the XSD’s through the applications class path and reference it accordingly in the XML file.
I did this for an activemq configuration as follows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.org/config/1.0"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://activemq.org/config/1.0 activemq-core-5.0.0.xsd
http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">
...
In this example, the XML file activemq-core-5.0.0.xsd will be retreived from the classpath (residing in the default package). Putting the XSD into a subpackage on the classpath or using a classpath:// URI has not worked for me in spring 2.5.2 (and other systems). There appear to be a couple of parsers with only very basic classpath resource retreival capabilities.
This entry was posted on Saturday, May 10th, 2008 at 13:50. Posted in: J2EE, System architecture, java, spring. You can follow any responses to this entry through the RSS 2.0feed. You can leave a response, or trackback from your own site.
