Browse Source

Merge branch '3.5.x'

Closes gh-47214
pull/47229/head
Phillip Webb 3 months ago
parent
commit
e9c08b8dcc
  1. 12
      module/spring-boot-cache/src/main/java/org/springframework/boot/cache/autoconfigure/CacheCondition.java

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

@ -27,7 +27,7 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata; import org.springframework.util.Assert;
/** /**
* General cache condition used with all cache configuration classes. * General cache condition used with all cache configuration classes.
@ -40,10 +40,12 @@ class CacheCondition extends SpringBootCondition {
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
String sourceClass = ""; Assert.isInstanceOf(AnnotationMetadata.class, metadata);
if (metadata instanceof ClassMetadata classMetadata) { return extracted(context, (AnnotationMetadata) metadata);
sourceClass = classMetadata.getClassName();
} }
private ConditionOutcome extracted(ConditionContext context, AnnotationMetadata metadata) {
String sourceClass = metadata.getClassName();
ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass); ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass);
Environment environment = context.getEnvironment(); Environment environment = context.getEnvironment();
try { try {
@ -51,7 +53,7 @@ class CacheCondition extends SpringBootCondition {
if (!specified.isBound()) { if (!specified.isBound()) {
return ConditionOutcome.match(message.because("automatic cache type")); return ConditionOutcome.match(message.because("automatic cache type"));
} }
CacheType required = CacheConfigurations.getType(((AnnotationMetadata) metadata).getClassName()); CacheType required = CacheConfigurations.getType(metadata.getClassName());
if (specified.get() == required) { if (specified.get() == required) {
return ConditionOutcome.match(message.because(specified.get() + " cache type")); return ConditionOutcome.match(message.because(specified.get() + " cache type"));
} }

Loading…
Cancel
Save