Skip to content

Commit 0ad349a

Browse files
committed
Merge branch '3.4.x' into 3.5.x
Closes gh-47213
2 parents 3dbc767 + e2ecc61 commit 0ad349a

File tree

1 file changed

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

1 file changed

+8
-6
lines changed

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

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

3131
/**
3232
* General cache condition used with all cache configuration classes.
@@ -39,18 +39,20 @@ class CacheCondition extends SpringBootCondition {
3939

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

0 commit comments

Comments
 (0)