Netbeans中JDK 16.0.2环境运行Spring Framework报类解析错误如何解决
问题根因
Unsupported class file major version 60是报错核心:JDK 16 编译生成的类文件主版本号为60,从你配置文件中引入的spring-beans-3.1.xsd可判断当前使用的是 Spring 3.1.x 版本,该版本依赖的 ASM 字节码解析工具仅支持更低版本的JDK类格式,无法解析JDK16编译的类文件。
解决方案
方案1:升级Spring Framework(推荐)
Spring 5.3.x 及更高版本正式兼容JDK 16,将项目中所有Spring依赖(spring-core、spring-context、spring-beans等)升级到5.3.x或更高稳定版本即可。
- Maven/Gradle项目:直接修改依赖配置中的Spring版本号,刷新依赖后重新构建
- 手动导入jar包项目:下载对应版本的Spring官方jar包,替换项目中原有旧版本Spring jar包
升级后可将配置文件中xsd地址的版本号去掉,改为通用地址,避免后续版本不匹配问题:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd "> <context:component-scan base-package="springanotaciones"></context:component-scan> </beans>
原有业务代码不需要修改,可直接兼容运行。
方案2:不升级Spring,降低编译字节码版本
如果暂时不需要高版本Spring特性,可将项目编译的目标字节码版本降到Spring 3.1支持的JDK版本,操作步骤:
- 打开NetBeans项目属性面板,进入
构建 > 编译设置页 - 将
源代码版本和生成的类文件的二进制版本都改为1.7 - 清理项目后重新构建启动即可
内容的提问来源于stack exchange,提问作者Mix
相关产品推荐
相关产品推荐

