HowToDoInJava

  • Python
  • Java
  • Spring Boot
  • Dark Mode
Home / Spring Core / Spring version-less schema for latest version

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 !!

Was this post helpful?

Let us know if you liked the post. That’s the only way we can improve.
TwitterFacebookLinkedInRedditPocket

About Lokesh Gupta

A family guy with fun loving nature. Love computers, programming and solving everyday problems. Find me on Facebook and Twitter.

Feedback, Discussion and Comments

  1. Arpit Chinmay

    May 7, 2018

    Hi,
    i’m new to Spring and while learning i encountered this error and could not resolve it.I did a little research and there is no article in stackOverflow that explains this.

    cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘context:property-placeholder’.

    <?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 ">
                     
            <context:property-placeholder location="classpath:sport.properties"/>
                    
            <bean id = "myFortune"
                  class =  "com.love2code.springdemo.HappyFortuneService">  
            </bean>        
             
           <bean id = "myCoach"
                 class = "com.love2code.springdemo.TrackCoach">
           <constructor-arg ref= "myFortune" />
           </bean>          
           
           <bean id="myCricketCoach"
                class = "com.love2code.springdemo.CricketCoach">
                <property name = "fortuneService" ref = "myFortune" />
                
                <!-- reference the loaded values from the properties file -->
                <property name = "emailAddress" value = "${foo.email}"/>
                <property name="name" value = "${foo.name}"/>
          </bean>
    </beans>
    
  2. Amol Gangawane

    July 19, 2016

    Is it applicable to spring -security xsd also??

    • Lokesh Gupta

      July 19, 2016

      Yes.

  3. Gaurav Sachdeva

    September 16, 2015

    How to remove version in this “”http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>””
    This is showing error in Web.xml
    Thanks

    • Lokesh Gupta

      September 16, 2015

      Please check the version of servlets jar in classpath. It should match with xsd version. More info : https://stackoverflow.com/questions/12146247/java-web-app-what-determines-my-servlet-api-version-does-it-get-specified-in

  4. Kwen

    April 28, 2014

    Hello,
    I’m using Spring 3.0.7.RELEASE but i have some problems with eclipse validation, the attribute local in “” cannot found in XSD if i remove the version in schemaLocation.

    How can I do ?

    My application-context :

    Thanx for help

    • Lokesh Gupta

      April 28, 2014

      Please put the code in code tag

      • Kwen

        April 28, 2014

        Sorry, i replace some characters by “-”

        -?xml version=”1.0″ encoding=”UTF-8″?-
        -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-3.0.xsd“-
        -bean id=”myDaoTarget” class=”com.test.dao.MyDaoImpl”/-
        -bean id=”myDao” class=”org.springframework.aop.framework.ProxyFactoryBean”-
        -property name=”proxyInterfaces” value=”com.test.dao.MyDao” /-
        -property name=”target”–ref local=”myDaoTarget”/–/property-
        -/bean-
        -/beans-

        • Lokesh Gupta

          April 29, 2014

          The http://www.springframework.org/schema/beans/spring-beans.xsd actually points to the 4.0 XSD, which does NOT have local. Use schemaLocation or version number.

          • Kwen

            April 29, 2014

            Ok Thanx u 🙂

  5. Jayakumar Jayaraman

    February 10, 2014

    That’s nice to know. Are there any impact because of this feature ?

    For instance we might be developing a project currently on 3.2.0 and at a later period if it refers to 5.0,…… any impact ?
    How how it affects related to the maven pom dependencies ?

    Thanks
    Jay

    • Lokesh Gupta

      February 10, 2014

      It will impact only when you use the config tags introduced in newer versions and you have old schema references.

  6. goni

    February 4, 2014

    nice

Comments are closed on this article!

Search Tutorials

Spring Tutorial

  • Spring – Introduction
  • Spring – IoC Containers
  • Spring – IoC vs. DI
  • Spring – Bean Scopes
  • Spring – Bean Life Cycle
  • Spring – Bean Postprocessors
  • Spring – Autowiring
  • Spring – Annotations
  • Spring – Stereotype Annotations
  • Spring – Task Scheduling
  • Spring – Timer Task
  • Spring – Events
  • Spring – Message Source
  • Spring – ResourceLoader
  • Spring – Property Editor
  • Spring – Send Email
  • Spring – Version-less Schema
  • Spring – Interview Questions
  • Spring – Best Practices

Meta Links

  • About Me
  • Contact Us
  • Privacy policy
  • Advertise
  • Guest and Sponsored Posts

Recommended Reading

  • 10 Life Lessons
  • Secure Hash Algorithms
  • How Web Servers work?
  • How Java I/O Works Internally?
  • Best Way to Learn Java
  • Java Best Practices Guide
  • Microservices Tutorial
  • REST API Tutorial
  • How to Start New Blog

Copyright © 2020 · HowToDoInjava.com · All Rights Reserved. | Sitemap

  • Sealed Classes and Interfaces