Lettuce Redis连接池配置不生效的常见原因是缺少 enabled 参数的显式设置和 commons-pool2 依赖。在 Spring Boot 中配置 Lettuce 连接池时,即使设置了 min-idle、max-idle 和 max-active 等参数,如果没有显式设置 enabled=true,连接池是否启用取决于 COMMONS_POOL2_AVAILABLE 变量。该变量通过 ClassUtils.isPresent("org.apache.commons.pool2.ObjectPool", ...) 判断类路径中是否存在 commons-pool2 依赖。如果项目未引入该依赖,即使配置了各种连接池参数,实际上连接池也不会生效,所有请求将复用单一连接。解决方案是在 Maven 或 Gradle 中引入 org.apache.commons:commons-pool2 依赖,同时显式设置 spring.redis.lettuce.pool.enabled=true。
加载中...