Spring/Java error: namespace element ‘annotation-config’ … on JDK 1.5 and higher

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.

Leave a Comment