Saturday 17 September 2016

Spring configuration files XML schema versions

Background

If you have previously worked on a Spring web project then you must have come across Spring configuration files. They are xmls which will have references to to the namespace they are using and the version they are pointing to. Pick up any one of the Spring post we have seen before -
You would see spring configurations files something like -

<beans xmlns="http://www.springframework.org/schema/beans"
    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-2.5.xsd">


Notice the 2.5 version. I mean it's pretty old now. You can find all the schema versions here -
 But as your project improves who cares about updating these files right? You update the spring version(jars) perhaps as you go forward but these configuration files remain as is. Lets see how we can resolve this problem.

Spring configuration XML schema: with or without version?

So how do you resolve this you ask? Do not specify the version. Yes I repeat do not specify the version. It should be something like -

<beans xmlns="http://www.springframework.org/schema/beans"
    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">

When you do not specify any version it will take that latest schema that you have in your classpath jar and that will upgrade with the version of jar you upgrade. Spring schema versions are in a file called spring.schemas in spring-beans jar file -



 From this file it will take the latest schema version without you need to worrying about it.



NOTE : You should try to move completely move away from Spring xml configurations. You should start using Java class based configurations and annotations.


Related Links

t> UA-39527780-1 back to top