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 !!
Arpit Chinmay
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’.
Amol Gangawane
Is it applicable to spring -security xsd also??
Lokesh Gupta
Yes.
Gaurav Sachdeva
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
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
Kwen
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
Please put the code in code tag
Kwen
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
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
Ok Thanx u 🙂
Jayakumar Jayaraman
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
It will impact only when you use the config tags introduced in newer versions and you have old schema references.
goni
nice