From b5abbf6b55a5ba13e4e22547e18f10da33876d46 Mon Sep 17 00:00:00 2001 From: erabii Date: Mon, 19 Feb 2024 22:10:25 +0200 Subject: [PATCH] fix (#1338) --- .../cloud/context/named/NamedContextFactory.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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 b6ed94a75..53732979a 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 T getInstance(String name, Class clazz, Class... generics) { public 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;