fix(cache): 缺 StringRedisTemplate Bean 时自动装配优雅退场

原仅 @ConditionalOnClass(类在 classpath 恒真),StringRedisTemplate Bean 缺失
(多 ConnectionFactory 致 @ConditionalOnSingleCandidate 不满足,或 exclude
RedisAutoConfiguration)时会因构造参数缺依赖而启动失败。加
@ConditionalOnBean(StringRedisTemplate),配合既有
@AutoConfigureAfter(RedisAutoConfiguration) 在 Redis 装配后求值,缺 Bean 时整类
back off 而非报错。仅改 cache,不动 stream(接受两者风格暂不一致)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
root
2026-06-26 09:58:00 +08:00
parent 1e673cdf83
commit 8b90fe099e
2 changed files with 13 additions and 0 deletions

View File

@@ -40,6 +40,17 @@ class RedisCacheAutoConfigurationTest {
});
}
@Test
void backsOffWhenNoStringRedisTemplateBean() {
// 不装配 RedisAutoConfiguration,上下文内无 StringRedisTemplate Bean:
// 应整类 back off 优雅退场,而非因缺依赖启动失败。
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(RedisCacheAutoConfiguration.class))
.run(ctx -> assertThat(ctx)
.hasNotFailed()
.doesNotHaveBean(RedisCacheEnhanceTemplate.class));
}
@Configuration
static class CustomConfig {
@Bean