How Spring Finds XSD File From Class Path

In our spring configuration, we put the beans tag as follows:

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

Now spring should find out from my calsspath the location of the spring-beans.xsd and spring-context.xsd files.

I found several xsd files along this path:

spring -context-4.1.5.RELEASE.jar / org / springframework / context / configuration

 spring-context-2.5.xsd spring-context-3.0.xsd spring-context-3.1.xsd spring-context-3.2.xsd spring-context-4.0.xsd spring-context-4.1.xsd 

When searching for spring - beans.xsd file, I found several files along this path:

spring - beans -4.1.5.RELEASE.jar / org / springframework / beans / factory / XML

 spring-beans-2.5.xsd spring-beans-3.0.xsd spring-beans-3.1.xsd spring-beans-3.2.xsd spring-beans-4.0.xsd spring-beans-4.1.xsd 

How spring will know where to look for this file, since there is no connection between the location of the schema in the beans tag and the actual location of this file. I can also find files like this spring-beans-<version>.xsd , while spring will know what spring-beans.xsd , even if we don’t specify any version in the <beans> .

+7
java spring xml xsd
source share
1 answer

Some spring libraries contain some file, for example META-INF / spring.schemas

The properties file named "spring.schemas" contains an XML mapping. Schema location (mentioned along with the schema declaration in XML files that use the schema as part of the "xsi: schemaLocation" attribute) to class path resources. This file is necessary to prevent spring from completely using the standard EntityResolver, which requires Internet access to access the schema file. If you specify a mapping in this properties file, spring will look for a schema in the classpath

eg.

spring.schemes spring - beans -xxx-RELEASE.jar

 http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd 

In the few words above, the properties allow you to map an XSD resource to the schemaLocation attribute.

+6
source share

All Articles