java.lang.IllegalArgumentException
at org.springframework.asm.ClassReader.<init>(Unknown Source)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130)
...
org.springframework.asm.ClassReader 是 Spring 內嵌的字節碼解析庫(基於 ASM)。異常 IllegalArgumentException 通常因:
maven.compiler.target)高於運行時 Spring 版本支援上限。| Spring 版本 | 內嵌 ASM 版本 | 支援最高 JDK |
|---|---|---|
| 3.2.x | 3.3.1 | JDK 7 (class 51.0) |
| 4.0.x - 4.3.x | 5.0.x | JDK 8 (class 52.0) |
| 5.0.x - 5.2.x | 7.0 - 7.1 | JDK 10 (class 54.0) |
| 5.3+ / Spring Boot 2.4+ | 9.0+ | JDK 17 (class 61.0) |
pom.xml 設定 <maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target>,確保生成 class 版本 ≤ 52.0。<dependency>
<groupId>some.thirdparty</groupId>
<artifactId>artifact</artifactId>
<exclusions>
<exclusion><groupId>org.springframework</groupId><artifactId>spring-core</artifactId></exclusion>
</exclusions>
</dependency>
javap -verbose MyClass.class | findstr "major",major version 52=JDK8, 55=JDK11, 61=JDK17。mvn clean install -U 或 IDE Invalidate Caches / Restart。若升級 Spring 後仍報錯,啟用 -verbose:class 觀察 ClassReader 載入路徑,確認是否仍有舊版 spring-core 被類加載器讀取。使用 mvn dependency:tree | grep spring 檢查依賴衝突。
「Context initialization failed」伴隨 asm.ClassReader.IllegalArgumentException 幾乎 100% 為版本不匹配。核心對策:Spring 版本 ≥ JDK 版本要求,或 編譯版本 ≤ Spring 支援上限。