Spring2.5与JDK8的集成问题
Spring2.5不支持JDK8及其以上的版本,因为有一段校验JDK版本的代码,当JDK版本大于1.7之后,会识别成JDK1.4之前的。会报版本太低的错误。
1 /* 2 * Copyright 2002-2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.core; 18 19 /** 20 * Internal helper class used to find the Java/JDK version 21 * that Spring is operating on, to allow for automatically 22 * adapting to the present platform's capabilities. 23 * 24 * <p>Note that Spring requires JVM 1.4 or higher, as of Spring 2.5. 25 * 26 * @author Rod Johnson 27 * @author Juergen Hoeller 28 * @author Rick Evans 29 */ 30 public abstract class JdkVersion { 31 32 /** 33 * Constant identifying the 1.3.x JVM (JDK 1.3). 34 */ 35 public static final int JAVA_13 = 0; 36 37 /** 38 * Constant identifying the 1.4.x JVM (J2SE 1.4). 39 */ 40 public static final int JAVA_14 = 1; 41 42 /** 43 * Constant identifying the 1.5 JVM (Java 5). 44 */ 45 public static final int JAVA_15 = 2; 46 47 /** 48 * Constant identifying the 1.6 JVM (Java 6). 49 */ 50 public static final int JAVA_16 = 3; 51 52 /** 53 * Constant identifying the 1.7 JVM (Java 7). 54 */ 55 public static final int JAVA_17 = 4; 56 public static final int JAVA_18 = 4; 57 58 59 private static final String javaVersion; 60 61 private static final int majorJavaVersion; 62 63 static { 64 javaVersion = System.getProperty("java.version"); 65 // version String should look like "1.4.2_10" 66 if(javaVersion.indexOf("1.8.") != -1){ 67 majorJavaVersion = JAVA_18; 68 }else if (javaVersion.indexOf("1.7.") != -1) { 69 majorJavaVersion = JAVA_17; 70 } 71 else if (javaVersion.indexOf("1.6.") != -1) { 72 majorJavaVersion = JAVA_16; 73 } 74 else if (javaVersion.indexOf("1.5.") != -1) { 75 majorJavaVersion = JAVA_15; 76 } 77 else { 78 // else leave 1.4 as default (it's either 1.4 or unknown) 79 majorJavaVersion = JAVA_14; 80 } 81 } 82 83 84 /** 85 * Return the full Java version string, as returned by 86 * <code>System.getProperty("java.version")</code>. 87 * @return the full Java version string 88 * @see System#getProperty(String) 89 */ 90 public static String getJavaVersion() { 91 return javaVersion; 92 } 93 94 /** 95 * Get the major version code. This means we can do things like 96 * <code>if (getMajorJavaVersion() < JAVA_14)</code>. 97 * @return a code comparable to the JAVA_XX codes in this class 98 * @see #JAVA_13 99 * @see #JAVA_14 100 * @see #JAVA_15 101 * @see #JAVA_16 102 * @see #JAVA_17 103 */ 104 public static int getMajorJavaVersion() { 105 return majorJavaVersion; 106 } 107 108 /** 109 * Convenience method to determine if the current JVM is at least Java 1.4. 110 * @return <code>true</code> if the current JVM is at least Java 1.4 111 * @see #getMajorJavaVersion() 112 * @see #JAVA_14 113 * @see #JAVA_15 114 * @see #JAVA_16 115 * @see #JAVA_17 116 */ 117 public static boolean isAtLeastJava14() { 118 return true; 119 } 120 121 /** 122 * Convenience method to determine if the current JVM is at least 123 * Java 1.5 (Java 5). 124 * @return <code>true</code> if the current JVM is at least Java 1.5 125 * @see #getMajorJavaVersion() 126 * @see #JAVA_15 127 * @see #JAVA_16 128 * @see #JAVA_17 129 */ 130 public static boolean isAtLeastJava15() { 131 return getMajorJavaVersion() >= JAVA_15; 132 } 133 134 /** 135 * Convenience method to determine if the current JVM is at least 136 * Java 1.6 (Java 6). 137 * @return <code>true</code> if the current JVM is at least Java 1.6 138 * @see #getMajorJavaVersion() 139 * @see #JAVA_16 140 * @see #JAVA_17 141 */ 142 public static boolean isAtLeastJava16() { 143 return getMajorJavaVersion() >= JAVA_16; 144 } 145 146 }
将相关的类文件打开源码,修改成如上的代码,编译后,替换jar包中的class文件即可