You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Java8至Java17+Spring Boot3.1.2时遇Unable to load cache item报错

Spring Boot 3.1.2(Java 17)升级运行异常:Unable to load cache item 解决

问题描述

将应用从Java 8升级到Spring Boot 3.1.2(搭配Java 17)后,应用可正常构建,但运行时抛出初始化异常,核心错误提示为Unable to load cache item,底层原因是org.springframework.asm.Item类缺少方法void set(int, java.lang.String, java.lang.String, java.lang.String)。

异常栈信息

Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.springframework.context.annotation.ConfigurationClassEnhancer.newEnhancer(ConfigurationClassEnhancer.java:121)
        at org.springframework.context.annotation.ConfigurationClassEnhancer.enhance(ConfigurationClassEnhancer.java:109)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:531)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:308)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:358)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:150)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:771)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:589)
        at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:93)
        at com.jpmc.cib.payments.psfxEmailNotification.processor.EmailNotificationJob.<clinit>(EmailNotificationJob.java:25)
Caused by: java.lang.IllegalStateException: Unable to load cache item
        at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:79)
        at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:105)
        at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:278)
        at org.springframework.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221)
        at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:174)
        at org.springframework.cglib.core.KeyFactory.create(KeyFactory.java:153)
        at org.springframework.cglib.proxy.Enhancer.<clinit>(Enhancer.java:73)
        ... 10 more
Caused by: java.lang.NoSuchMethodError: 'void org.springframework.asm.Item.set(int, java.lang.String, java.lang.String, java.lang.String)'
        at org.springframework.asm.ClassWriter.newClassItem(ClassWriter.java:1110)
        at org.springframework.asm.ClassWriter.newClass(ClassWriter.java:1131)
        at org.springframework.asm.ClassWriter.visit(ClassWriter.java:669)
        at org.springframework.asm.ClassVisitor.visit(ClassVisitor.java:121)
        at org.springframework.cglib.core.DebuggingClassWriter.visit(DebuggingClassWriter.java:60)
        at org.springframework.cglib.core.ClassEmitter.begin_class(ClassEmitter.java:83)
        at org.springframework.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:249)
        at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
        at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:312)
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:85)
        at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:83)
        at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
        ... 17 more

当前依赖配置

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.asm</artifactId>
    <version>3.1.2.RELEASE</version>
</dependency>

解决方案

  • 移除手动引入的org.springframework.asm依赖:Spring Boot 3.1.2的依赖管理体系已经内置了适配Java 17的ASM相关依赖,你手动添加的3.1.2.RELEASE版本是Spring Framework 3.x时期的老旧依赖,和Spring Boot 3.x的依赖版本严重不兼容,导致方法缺失。
  • 确保使用Spring Boot依赖管理:通过spring-boot-starter-parent作为项目父依赖,或者引入spring-boot-dependencies依赖管理,让Spring Boot自动管控所有Spring相关组件的版本,避免版本冲突问题。

内容的提问来源于stack exchange,提问作者rao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 10:54:51