diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java index b6ed94a7..53732979 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/named/NamedContextFactory.java @@ -67,11 +67,11 @@ public abstract class NamedContextFactory contexts = new ConcurrentHashMap<>(); - private Map configurations = new ConcurrentHashMap<>(); + private final Map configurations = new ConcurrentHashMap<>(); private ApplicationContext parent; - private Class defaultConfigType; + private final Class defaultConfigType; public NamedContextFactory(Class defaultConfigType, String propertySourceName, String propertyName) { this(defaultConfigType, propertySourceName, propertyName, new HashMap<>()); @@ -222,11 +222,9 @@ public abstract class NamedContextFactory T getInstance(String name, ResolvableType type) { GenericApplicationContext context = getContext(name); String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, type); - if (beanNames.length > 0) { - for (String beanName : beanNames) { - if (context.isTypeMatch(beanName, type)) { - return (T) context.getBean(beanName); - } + for (String beanName : beanNames) { + if (context.isTypeMatch(beanName, type)) { + return (T) context.getBean(beanName); } } return null;