《转载》 解决AnnotationTransactionAttributeSource is only available on Java 1.5 and highe

参考文献:

https://www.cnblogs.com/llfddmm/p/10521113.html


https://stackoverflow.com/questions/33891697/annotationawareaspectjautoproxycreator-is-only-available-on-java-1-5-and-higher


https://stackoverflow.com/questions/23813369/spring-java-error-namespace-element-annotation-config-on-jdk-1-5-and-high/32487035#32487035

 

情景描述:

运维的老项目,使用spring2.5 和 jdk1.7,但是在部署时,由于是和另一个已有项目使用同一台服务器,所以必须使用 jdk1.8。

在tomcat上部署该项目时报错:

AnnotationTransactionAttributeSource is only available on Java 1.5 and highe

出现该问题,主要是对xml文件中的        处理时出现了问题。

针对该问题的解决方案包括:

(1)将jdk版本由  jdk1.8 换为 jdk1.7;

(2)将项目的spring版本,由spring2.5  升级为 spring4;

(3)手动修改spring的jar包,在org.springframework.core目录下,有一个JdkVersion.class,自己参照包路径,重新写一个JdkVersion.java,如下所示:

package org.springframework.core;
     
    public 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;
        
        //for jre 1.8
        public static final int JAVA_18 = 5;

        
        private static final String javaVersion = System.getProperty("java.version");
        
        private static final int majorJavaVersion;
        
        public static String getJavaVersion()
        {
            return javaVersion;
        }
        
        public static int getMajorJavaVersion()
        {
            return majorJavaVersion;
        }
        
        public static boolean isAtLeastJava14()
        {
            return true;
        }
        
        public static boolean isAtLeastJava15()
        {
            return getMajorJavaVersion() >= 2;
        }
        
        public static boolean isAtLeastJava16()
        {
            return getMajorJavaVersion() >= 3;
        }
        
        static
        {
            //for jre 1.8
            if (javaVersion.indexOf("1.8.") != -1)
            {
                majorJavaVersion = 5;
            }

            else if (javaVersion.indexOf("1.7.") != -1)
            {
                majorJavaVersion = 4;
            }
            else if (javaVersion.indexOf("1.6.") != -1)
            {
                majorJavaVersion = 3;
            }
            else if (javaVersion.indexOf("1.5.") != -1)
            {
                majorJavaVersion = 2;
            }
            else
            {
                majorJavaVersion = 1;
            }
        }
    }


写好之后,编译成.class文件,放到spring的jar包中,替换项目jar包,重新启动,就好了。

 

 

基于我的情况,选择了第(3)中解决方案,替换spring-core.jar之后,问题解决。

 

你可能感兴趣的:(spring)