ERROR : Context namespace element ‘annotation-config’ and its parser class :
[org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher
Description : My project is using :
- server – Tomcat8
- java- 1.8
- Framework – Spring 2.5
I had added all the jar files required for spring framework. But when I tried to deploy my project, it gave below error :
Error :
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document;
nested exception is **java.lang.IllegalStateException: Context namespace element ‘annotation-config’ and its parser class [org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser] are only available on JDK 1.5 and higher**
How did I resolve it?
I upgraded my spring jar files with 4.2.5 and it worked.
Why?
The class that is throwing the exception is using below code to check for Java version :
static { javaVersion = System.getProperty("java.version"); // version String should look like "1.4.2_10" if (javaVersion.indexOf("1.7.") != -1) { majorJavaVersion = JAVA_17; } else if (javaVersion.indexOf("1.6.") != -1) { majorJavaVersion = JAVA_16; } else if (javaVersion.indexOf("1.5.") != -1) { majorJavaVersion = JAVA_15; } else { // else leave 1.4 as default (it's either 1.4 or unknown) majorJavaVersion = JAVA_14; } }
When Spring 2.5 was first released, the code did not assume it will run in a Java version that is higher than 1.7.
For Java 8 and beyond, the code above will assume default 1.4 version. Because of this, the annotations part will complain. So, I upgraded my spring jar files with 4.2.5 and it worked.