Note: the test project I\'m mentioning can be downloaded with:
git clone https://github.com/mperdikeas/so-spring-di-appcontext-schemalocation.git
.. and run
Here is what happens:
XML schema allows you to define aliases (short names) to XML namespaces. Technically all namespaces are identified by full URI but that would be very cumbersome - so you can use short aliases like context
and p
. There is also a default namespace denoted by xmlns
attribute
By default XML parsers assume namespace URI is also a XSD file URL location. This is often the case, but is not required by the spec. This is also how XML parser in Spring works if you don't provide schemaLocation
attribute.
schemaLocation
is used to map from namespace URI to XSD file physical location (URL). It is used when schema namespace does not point to valid XSD URL (see MSDN on schemaLocation).
Last but not least, Spring adds yet another layer that translates Internet URLs to local files on CLASSPATH. This way your application can start without Internet connection (or when springframework.org site is down).
If you search your project libraries you'll find several files named spring.schemas
. These files contain lines similar to below (extract from the file found in spring-context.jar
, I added alignment):
http\://www.springframework.org/schema/context/spring-context.xsd= org/springframework/context/config/spring-context-3.1.xsd
http\://www.springframework.org/schema/jee/spring-jee.xsd= org/springframework/ejb/config/spring-jee-3.1.xsd
http\://www.springframework.org/schema/lang/spring-lang.xsd= org/springframework/scripting/config/spring-lang-3.1.xsd
http\://www.springframework.org/schema/cache/spring-cache.xsd= org/springframework/cache/config/spring-cache-3.1.xsd