Skip to content

Commit e9c08b8

Browse files
committed
Merge branch '3.5.x'
Closes gh-47214
2 parents 1de09fb + 0ad349a commit e9c08b8

File tree

1 file changed

+8
-6
lines changed
  • module/spring-boot-cache/src/main/java/org/springframework/boot/cache/autoconfigure

1 file changed

+8
-6
lines changed

module/spring-boot-cache/src/main/java/org/springframework/boot/cache/autoconfigure/CacheCondition.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.springframework.core.env.Environment;
2828
import org.springframework.core.type.AnnotatedTypeMetadata;
2929
import org.springframework.core.type.AnnotationMetadata;
30-
import org.springframework.core.type.ClassMetadata;
30+
import org.springframework.util.Assert;
3131

3232
/**
3333
* General cache condition used with all cache configuration classes.
@@ -40,18 +40,20 @@ class CacheCondition extends SpringBootCondition {
4040

4141
@Override
4242
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
43-
String sourceClass = "";
44-
if (metadata instanceof ClassMetadata classMetadata) {
45-
sourceClass = classMetadata.getClassName();
46-
}
43+
Assert.isInstanceOf(AnnotationMetadata.class, metadata);
44+
return extracted(context, (AnnotationMetadata) metadata);
45+
}
46+
47+
private ConditionOutcome extracted(ConditionContext context, AnnotationMetadata metadata) {
48+
String sourceClass = metadata.getClassName();
4749
ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass);
4850
Environment environment = context.getEnvironment();
4951
try {
5052
BindResult<CacheType> specified = Binder.get(environment).bind("spring.cache.type", CacheType.class);
5153
if (!specified.isBound()) {
5254
return ConditionOutcome.match(message.because("automatic cache type"));
5355
}
54-
CacheType required = CacheConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
56+
CacheType required = CacheConfigurations.getType(metadata.getClassName());
5557
if (specified.get() == required) {
5658
return ConditionOutcome.match(message.because(specified.get() + " cache type"));
5759
}

0 commit comments

Comments
 (0)