Spring / Java Error: namespace element 'annotation-config' ... on JDK 1.5 and later

I have a Spring / Java application that is compiled with a compiler compliance level of 1.5 .

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

I downloaded JDK 8u5 .

I set the path in bash as follows:

PATH=$PATH:$HOME/jdk1.8.0_05/bin export PATH 

Java Conversion 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 install in setnenv.sh (for Tomcat):

 JDK_HOME=/home/userid/jdk1.8.0_05 

When I deploy my WAR file, I get below the error. I think Tomcat does not seem to use the installed Java. I followed the installation instructions. PS: I also tried JRE instead of JDK the same problem.

 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 
+53
java spring illegalstateexception
May 22 '14 at 17:19
source share
10 answers

The class that throws the exception uses this code to check the version of Java:

 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 either 1.4 or unknown) majorJavaVersion = JAVA_14; } } 

So, when Spring 2.5 was first released, the code did not assume that it would run in a version of Java later than 1.7. For Java 8 and above, the code above will use version 1.4 by default. Because of this, some annotations will complain.

It seems to me that you need to either upgrade the Spring version, or use Java 7. Spring 2.5 has been EOLed for quite some time, anyway.

+112
May 22 '14 at 19:09
source share

I have a similar problem. Old Spring MVC / Spring Faces application in Spring 2.5.5 does not start on Java 8.

I spent a few days finding a solution because we need to run Java 8.

The first idea was: upgrade the full Spring package to 4.1.6. I used Maven. The problem with this method is that after that it is necessary to rework almost the entire project. This is because, for example, in Spring 4, the JSF implementation and some special taglib that were completely removed, for example, <sf:..> , were removed. And there were some more serious and minor issues with the configuration, adapters, handlers, mappings ....

The second approach was to partially replace the JARs with the w760. One on one. Not success again. It is impossible to replace any jar without affecting addiction.

I believe that in a few weeks or months of struggle I can succeed on both approaches. But not much time. And I gave up. My decision:

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

 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 really not necessary, just for fun.It because this source came from the Spring 3.0.0 package, where the Spring guys have already changed the Java version check. Versions over 7 are not considered old java.

Now the application starts correctly. It calls the JdkVersion class from my project instead of jar.

It still works! Thanks to everyone for this topic who gave this idea.

thank

+12
Apr 15 '15 at 10:34
source share
 <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> 

TO =>

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.4.RELEASE</version> </dependency> 

OR

  • Right-click the project property.
  • Go to / Click "Java Build Path".
  • Select the Libraries tab and double-click JRE System Libry
  • From this pop-up menu, select JDK 1.7 (If you do not have JDK 1.7, first install it, then select it from the "runtime").

Property

+9
Apr 04 '15 at 9:19
source share

I need to support Spring 2.5.5 on Java 8, so I used this approach from this answer to provide the option of replacing in the future to replace JdkVersion.class with as few side effects as possible (no one published the full class, and I did not want to carry away another answer). There is no need to test Java 8, just the default on Java 7, which is the highest version the class cared for:

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 at the corresponding version of JdkVersion.java and use this as a starting point (the example below is for Spring 2.5.5, and you do not want to change the method signatures from the version you are 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 originally compiled as the target 48.0 ( looking at it , we find that it 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 flags: ACC_PUBLIC, ACC_SUPER, ACC_ABSTRACT Constant pool: ... 

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

 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; static { 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 version of major.minor as above if necessary.

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

jar Mcf ../spring-modified.jar *

Copy the modified jar file if necessary (like spring.jar or, if necessary).

+7
Sep 09 '15 at 18:44
source share

I turned out to be another unsuccessful user of a very old project (developed in 2008!) That still uses Spring 2.5. And this is not a Maven project, so upgrading to later versions of Spring lasted a long time with dependency errors and gave build errors. I downgraded the JRE code to 1.7 and it worked fine.

Just document how to do this in eclipse if anyone needs help:

  • If you don't already have Java 7, download JDK 7 and install it somewhere like C:\Program Files\Java\jdk1.7.0_71

  • Then go to eclipse and double click on Servers > Tomcat vX.Y server

  • Click Runtime Environment , then Installed JREs

  • Then Add > Standard VM and click Next . You see a window like this:

    Adding a new JRE

  • Click Directory... and navigate to the folder where you installed the JDK (i.e. C:\Program Files\Java\jdk1.7.0_71 . The JDK is fine, there is no need for a JRE). Click Finish .

  • Then make sure you select the JRE for Java 7 and everything is installed.

+2
Dec 02 '14 at 22:48
source share

Move the spring version from 2.5 to> = 3.2.3.

For spring migration you need to make the following changes -

1) In your pom.xml, remove the dependency for spring 2.5.6 and add the dependency for the new spring version.

2) Update the "xsi: schemaLocation" in the beans tag of the applicationcontet.xml file of your project.

for example, upgrade http://www.springframework.org/schema/beans/spring-beans-2.5.xsd to http://www.springframework.org/schema/beans/spring-beans-3.2.xsd for spring version 3.2 .3.

3) Clean, build and redeploy your project.

+2
Nov 18 '15 at 9:31
source share

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

in the pom.xml replace project file:

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.6</version> </dependency> 

for

 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.4.RELEASE</version> </dependency> 

and say goodbye to your problems!

These two interdependencies are in most cases a substitute for a larger dependence.

0
Jan 16 '15 at 21:58
source share

I ran into the same problem. But trying very hard, I found out that this is due to the use of Java 1.8. I changed it to 1.6 and it worked.

0
Aug 08 '16 at 11:39 on
source share

I created a fully automatic version of valismortis answer. First read his post about the intricacies he addresses.

  • create an ant build file with the content under the tags
  • copy spring.jar next to the build file
  • run target patch
  • everything is ready, the file is fixed

assembly file contents:

 <project name="spring-patch" default="patch"> <target name="patch"> <mkdir dir="src/org/springframework/core"/> <get dest="src/org/springframework/core/JdkVersion.java" src="http://grepcode.com/file_/repo1.maven.org/maven2/org.springframework/spring/2.5.5/org/springframework/core/JdkVersion.java/?v=source&amp;disposition=attachment" /> <replace dir="src" value="majorJavaVersion = JAVA_17"> <replacetoken>majorJavaVersion = JAVA_14</replacetoken> </replace> <javac srcdir="src" /> <zip destfile="spring.jar" update="true"> <fileset dir="src" includes="**/*.class" /> </zip> <delete dir="src" /> </target> </project> 
0
Oct 29 '16 at 10:11
source share

Although this answer has been completely satisfied, in some cases it is undesirable or possible to upgrade the Java version or the Spring version.

In our case, we must use JDK 8 to communicate with Sonar (from Jenkins), and we do not want to change the spring version, because we do not have test capacity for testing this update.

Our solution was to simply override the Java version when building using

 -Djava.version=1.6.45 
0
Nov 27 '17 at 12:35
source share



All Articles