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

Spring Boot从2.5升级到3.1.2后找不到org.cache2k.integration包

Spring Boot 2.5升级到3.1.2后cache2k包缺失问题解决

问题说明

将Spring Boot从2.5版本升级到3.1.2后,项目构建时出现编译错误:

error: package org.cache2k.integration does not exist
import org.cache2k.integration.CacheLoader;

错误截图:
错误截图

当前build.gradle核心配置片段:

targetCompatibility = '17'

sourceCompatibility = '17'

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.2' apply false
    id 'io.spring.dependency-management' version '1.1.2' apply false      
}

问题根源

Spring Boot 3.x基于Spring Framework 6.x,依赖版本体系做了重大调整。cache2k的旧版本要么不再被Spring Boot默认依赖管理覆盖,要么与Java 17、Spring 6的兼容性不足,导致编译时无法找到对应的包。

解决方案

1. 显式添加兼容的cache2k依赖

在build.gradle的dependencies块中添加适配Spring Boot 3.x的cache2k版本,推荐使用官方最新稳定版(示例为2.6.1.Final,可根据实际情况调整):

dependencies {
    // 核心API包
    implementation 'org.cache2k:cache2k-api:2.6.1.Final'
    // 核心实现包
    implementation 'org.cache2k:cache2k-core:2.6.1.Final'
    // 如果用到Spring集成模块,添加此依赖
    implementation 'org.cache2k:cache2k-spring:2.6.1.Final'
}

根据项目实际使用的cache2k模块选择对应的依赖即可。

2. 调整依赖管理插件配置

如果之前将io.spring.dependency-management设置为apply false,需要确保该插件在主模块或子模块中正确启用,这样Spring Boot的依赖管理能辅助处理版本兼容问题:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.2'
    id 'io.spring.dependency-management' version '1.1.2'
}

3. 清理并重新构建项目

执行Gradle清理和构建命令,确保新依赖被正确下载并生效:

./gradlew clean build

验证

构建成功后,检查代码中org.cache2k.integration.CacheLoader的导入是否正常,运行项目确认缓存相关功能可正常使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:15:06