Spring/Java error: namespace element 'annotation-config' ... on JDK 1.5 and higher

context namespace element 'component-scan' and its parser class
annotationawareaspectjautoproxycreator is only available on java 1.5 and higher
java 1.5 or higher
spring context
spring core
spring package
spring 5
spring in java

I have Spring/Java App that is compiled with Compiler compliance level 1.5.

I have a new Linux setup where I downloaded Apache Tomcat 8.0.8.

I downloaded JDK 8u5.

I set the path in bash as follows:

export PATH

Java -version reports:

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

And set in setnenv.sh (for Tomcat):


When I deploy my WAR file I get below error. I think Tomcat doesn't seem to use the Java I installed. I have followed the setup instructions. PS: I also tried JRE instead of JDK and same issue.

22-May-2014 11:34:54.070 INFO [http-nio-8080-exec-4] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
22-May-2014 11:34:54.512 SEVERE [http-nio-8080-exec-4] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
 org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from file [/home/userid/apache-tomcat-8.0.8/webapps/myApplication-QA/WEB-INF/classes/config/spring/securityContext.xml]; 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**
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4750)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5170)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1270)
    at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:673)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:221)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:213)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:615)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:78)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1033)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: 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
    at org.springframework.context.config.ContextNamespaceHandler$1.parse(ContextNamespaceHandler.java:65)
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1253)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1243)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
    ... 49 more

22-May-2014 11:34:54.518 INFO [http-nio-8080-exec-4] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext

The class that's throwing the exception is using this 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;

So, when Spring 2.5 was first released, the code didn't assume it will be run in a Java version that's later 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.

I think you either need to upgrade your Spring version or use Java 7. Spring 2.5 has been EOLed for quite some time now, anyway.

tomcat annotation-config error spring 2.5 with java 1.8, I have Spring/Java App that is compiled with Compiler compliance level 1.5. I have a new Linux setup where I downloaded Apache Tomcat 8.0.8. I downloaded  Old Spring MVC/Spring Faces application under spring 2.5.5 doesn’t run on Java 8. I spent few days trying to find solution because we need to run Java 8. First idea was: to upgrade complete Spring package up to 4.1.6.

I have the similar problem. Old Spring MVC/Spring Faces application under spring 2.5.5 doesn't run on Java 8.

I spent few days trying to find solution because we need to run Java 8.

First idea was: to upgrade complete Spring package up to 4.1.6. I used Maven. Problem of this method that after that it is necessary to rework nearly the whole project. It is because for example in Spring 4 were removed JSF implementation and some special taglibs where completely removed, like <sf:..>. And were some more major and minor problems with configuration, adapters, handlers, mappings....

Second approach was to replace Spring JARs partially.One by one. Again no success. Impossible to replace any jar without touching dependencies.

I believe that after few weeks or monthes of struggling I can get success on both approaches. But have no so much time. And I gave up. My solution is:

I found source file JdkVersion.java from org.springframework.core package. http://www.java2s.com/Code/Jar/o/Downloadorgspringframeworkcoresources300releasejar.htm. I created org.springframework.core package in my project with only one class JdkVersion. After that made simple change of the code to check Java 8 version. Smth like that:

public static final int JAVA_18 = 5;


        javaVersion = System.getProperty("java.version");
    // version String should look like "1.4.2_10"
    if (javaVersion.contains("1.8.")) {
        majorJavaVersion = JAVA_18;         
        System.out.println("JAVA_VERSION: "+javaVersion);

    } else if (javaVersion.contains("1.7.")) {
        majorJavaVersion = JAVA_17;

Even this code change is not really necessary, only just for fun.It is because this source came from Spring 3.0.0 package where Spring guys already changed the Java version check. Versions higher than 7 are not considered as old java.

Now application starts properly. It call JdkVersion class from my project instead of jar.

Works so far! Thanks for all from this thread who gave this idea.


Context namespace element 'component-scan' and its parser class , IllegalStateException: Context namespace element 'annotation-config' and its parser class [org.springframework.context.annotation. What I can't explain is how this ever worked with Spring-WS 1.5.x - the namespace mismatch should fail for every version. Whatever tool you used to generate the JAXB classes should have produced a package-info.java file that declared the namespace. Are you sure it's not in there somewhere?

I need to support Spring 2.5.5 on Java 8, so I used the approach from this answer to provide a future-proof drop-in replacement for JdkVersion.class with as few side-effects as possible (nobody else posted a complete class, and I didn't want to hijack the other answer). There is no need to check for Java 8, simply default to Java 7, which is the highest version the class cared about:

Extract the jar file:

mkdir spring
cd spring
jar xvf ../spring.jar

Check the Spring version in META-INF/MANIFEST.MF (you should see something like version=2.5.5). Look up the appropriate version of JdkVersion.java and use that as a starting point (the example below is for Spring 2.5.5 and you don't want to change any method signatures from the version you're working with).

Check the major and minor version of the JdkVersion.class file:

javap -verbose org/springframework/core/JdkVersion.class

We see that the class was original compiled as target 48.0 (looking this up, we find that is Java 1.4):

Classfile /tmp/spring/org/springframework/core/JdkVersion.class
  Last modified Jun 23, 2008; size 1286 bytes
  MD5 checksum 98e6ea08ce9186c50cc71d14465fc3dd
  Compiled from "JdkVersion.java"
public abstract class org.springframework.core.JdkVersion
  minor version: 0
  major version: 48
Constant pool:

Create org/springframework/core/JdkVersion.java with the following content:

package org.springframework.core;

public abstract class JdkVersion
    public static final int JAVA_13 = 0;
    public static final int JAVA_14 = 1;
    public static final int JAVA_15 = 2;
    public static final int JAVA_16 = 3;
    public static final int JAVA_17 = 4;

    private static final String javaVersion;
    private static final int majorJavaVersion;

        javaVersion = System.getProperty("java.version");

        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 if (javaVersion.indexOf("1.4.") != -1) { // new
            majorJavaVersion = JAVA_14;                 // new
        } else {
            majorJavaVersion = JAVA_17;                 // changed from JAVA_14

    public static String getJavaVersion()
        return javaVersion;

    public static int getMajorJavaVersion()
        return majorJavaVersion;

    public static boolean isAtLeastJava14()
        return true;

    public static boolean isAtLeastJava15()
        return getMajorJavaVersion() >= JAVA_15;

    public static boolean isAtLeastJava16()
        return getMajorJavaVersion() >= JAVA_16;

Then compile the new class as Java 1.4:

javac -source 1.4 org/springframework/core/JdkVersion.java

You can check the major.minor version again as above if needed.

Create the modified jar file (without overwriting the original manifest):

jar Mcf ../spring-modified.jar *

Copy the modified jar file where needed (as spring.jar or as appropriate).

"Context namespace element 'annotation-config' and its parser class , You are correct that error does relate to the Java version and spring files. However, it's expected for a few old portlets in SSP-Platform(uPortal) like the  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Correct way to utilize p and util namespace in Spring XML Configuration


TO =>



  1. Right click on project property.
  2. Go to/ Click on "Java Build Path".
  3. Select Libraries tab and double click on "JRE System Libry"
  4. On that pop up select the JDK 1.7 (If you dont have JDK 1.7 ,first install it, then select it from "Execution environment")

Spring/Java error: namespace element 'annotation-config' … on JDK , "Context namespace element 'annotation-config' and its parser class" message by Spring Framework parsing XML document from ServletContext resource [/​WEB-INF/applicationContext.xml]; nested exception is java.lang. myBatis xml map causing namespace must be declared for element type mapper. Is there anything obvious wrong with this setup please. On app startup I get Attribute "namespace" must be declared for element type "mapper", when it clearly is declared. spring xml resource dao.xml:

i had the same problem, but i have a solution:

in your project file pom.xml replace:





and say good bye to your problems!!

This two dependecies are the replacement for the firts dependency in the most part.

spring example error (Spring forum at Coderanch), Spring/Java error: namespace element 'annotation-config' … on JDK 1.5 and higher. java spring illegalstateexception. I have Spring/Java App  You may look here for further information:. The tx tags deal with configuring all of those beans in Spring's comprehensive support for transactions. These tags are covered in the chapter entitled Chapter 9, Transaction management.

Java Spring, spring example error When I run MainApp.java getting below error ? Context namespace element 'annotation-config' and its parser class  You can find more information in the Spring Reference Documentation. A namespace element can be used simply to allow a more concise way of configuring an individual bean or, more powerfully, to define an alternative configuration syntax which more closely matches the problem domain and hides the underlying complexity from the user.

Spring Framework Reference Documentation, ERROR : Context namespace element 'annotation-config' and its parser class : [​org.springframework.context.annotation. Spring needs to know that the namespace is in use before actually using it, similar to declaring a variable. Namespace declaration needed for all versions of Spring – Reimeus Oct 7 '17 at 13:30 add a comment |

Spring Framework Reference Documentation, Using the JDBC core classes to control basic JDBC processing and error handling Code-based equivalents to popular Spring XML namespace elements  Spring/Java error: namespace element 'annotation-config' … on JDK 1.5 and higher (8) Even though this answer has been perfectly answered, in some cases it's not desired or possible to upgrade the Java version or the Spring version.

  • Try in setenv.sh: JAVA_HOME=/home/userid/jdk1.8.0_05
  • Thanks Stefan, I tried that and still no luck. BTW: On Tomcat startup I get below. bash startup.sh Using CATALINA_BASE: /home/userid/apache-tomcat-8.0.8 Using CATALINA_HOME: /home/userid/apache-tomcat-8.0.8 Using CATALINA_TMPDIR: /home/userid/apache-tomcat-8.0.8/temp Using JRE_HOME: /home/userid/jdk1.8.0_05 Using CLASSPATH: /home/userid/apache-tomcat-8.0.8/bin/bootstrap.jar:/home/userid/apache-tomcat-8.0.8/bin/tomcat-juli.jar Using CATALINA_PID: /home/userid/apache-tomcat-8.0.8/tomcat.pid Tomcat started.
  • You are using Spring 2.5?
  • Yes this is an old App.
  • @AndreiStefan replace jdk1.8... with a jdk 5, 6 or 7. Thanks for pointing me in the right direction. I encountered this problem because I got two apps running on the same machine - one requiring java 8, and one old one which depends on spring 2.5
  • Stefan, That was it. I downloaded JRE 1.7 and all is well. Thank you for your help. Robert
  • It appears like support for Java 8 was added in Spring >= 3.2.3. See the code change in JdkVersion.class.
  • Phew, this solution was simpler than I feared it would be. Thanks!
  • I have adapted this approach to my project which has multiple modules/subprojects in it. So what i did was i searched for the spring-xxx-version.jar on my server directory( i was using tomcat ). I added a JdkVersion.class (that has check for java 8 as described above) in to the spring-xxx-version.jar and re-started the server. that fixed my problem.
  • That's good as well, you just patched original spring jars. Anyway this version of spring is out of service.
  • This solved the issue for me. Thanks!