Spring version-less schema for latest version

If you have worked on Spring framework projects, then you must have seen spring context configuration files (e.g. applicationContext.xml) where in header you specify the schema references (.xsd) for various spring modules. In schema references, we mention the xml namespace and as well as schema version number.

Well specifying schema version number is not mandatory at all, and you can omit it. If fact, you should omit it all the time. Consider it as a best practice to follow.

Spring automatically picks the highest version available from the project dependencies (jars). Also, as the project evolves and the Spring version will be updated, we won’t have to maintain all the XML config files to see the new features.

Example of version-less Spring schema

With Schema Version

<?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:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context/ 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  
  <!-- Other bean definitions-->
  
</beans>

WITHOUT Schema Version

This can be written as:

<?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: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">

  
  <!-- Other bean definitions-->
  
</beans>

Drop me your questions in comments section.

Happy Learning !!

Comments

Subscribe
Notify of
guest
14 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode