Browse Source

Prevent unnecessary refresh for InjectionMetadata.EMPTY

Closes gh-24485
pull/24490/head
Juergen Hoeller 6 years ago
parent
commit
669a689a50
  1. 18
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

18
spring-beans/src/main/java/org/springframework/beans/factory/annotation/InjectionMetadata.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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<InjectedElement> checkedElements = new LinkedHashSet<>(this.injectedElements.size());
for (InjectedElement element : this.injectedElements) {
@ -153,7 +167,7 @@ public class InjectionMetadata { @@ -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));
}

Loading…
Cancel
Save