diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java index 1d1fbd77cb7..107aa580b58 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. +4 * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,6 +53,10 @@ public class InjectionMetadata { * @since 5.2 */ public static final InjectionMetadata EMPTY = new InjectionMetadata(Object.class, Collections.emptyList()) { + @Override + protected boolean needsRefresh(Class clazz) { + return false; + } @Override public void checkConfigMembers(RootBeanDefinition beanDefinition) { } @@ -89,6 +93,16 @@ public class InjectionMetadata { } + /** + * Determine whether this metadata instance needs to be refreshed. + * @param clazz the current target class + * @return {@code true} indicating a refresh, {@code false} otherwise + * @since 5.2.4 + */ + protected boolean needsRefresh(Class clazz) { + return this.targetClass != clazz; + } + public void checkConfigMembers(RootBeanDefinition beanDefinition) { Set checkedElements = new LinkedHashSet<>(this.injectedElements.size()); for (InjectedElement element : this.injectedElements) { @@ -153,7 +167,7 @@ public class InjectionMetadata { * @return {@code true} indicating a refresh, {@code false} otherwise */ public static boolean needsRefresh(@Nullable InjectionMetadata metadata, Class clazz) { - return (metadata == null || metadata.targetClass != clazz); + return (metadata == null || metadata.needsRefresh(clazz)); }