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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user