diff --git a/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/main/java/io/gravitee/gateway/reactive/handlers/api/v4/AbstractReactorFactory.java b/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/main/java/io/gravitee/gateway/reactive/handlers/api/v4/AbstractReactorFactory.java index c29b9195e4c..d040b1b31f4 100644 --- a/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/main/java/io/gravitee/gateway/reactive/handlers/api/v4/AbstractReactorFactory.java +++ b/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/main/java/io/gravitee/gateway/reactive/handlers/api/v4/AbstractReactorFactory.java @@ -47,6 +47,7 @@ import io.gravitee.resource.api.ResourceManager; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.context.ApplicationContext; @@ -153,10 +154,9 @@ public ApiReactor create(final T reactableApi) { protected List commonTemplateVariableProviders(T reactableApi) { final List templateVariableProviders = new ArrayList<>(); templateVariableProviders.add(new ApiTemplateVariableProvider(reactableApi)); - List list = applicationContext - .getBeansOfType(TemplateVariableProviderFactory.class) - .values() - .stream() + List list = Stream + .of(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, TemplateVariableProviderFactory.class)) + .map(name -> (TemplateVariableProviderFactory) applicationContext.getBean(name)) .filter(factory -> factory.getTemplateVariableScope() == TemplateVariableScope.API) .flatMap(factory -> factory.getTemplateVariableProviders().stream()) .toList(); diff --git a/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/test/java/io/gravitee/gateway/reactive/handlers/api/v4/DefaultApiReactorFactoryTest.java b/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/test/java/io/gravitee/gateway/reactive/handlers/api/v4/DefaultApiReactorFactoryTest.java index 01eb060893a..b5ec207538b 100644 --- a/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/test/java/io/gravitee/gateway/reactive/handlers/api/v4/DefaultApiReactorFactoryTest.java +++ b/gravitee-apim-gateway/gravitee-apim-gateway-handlers/gravitee-apim-gateway-handlers-api/src/test/java/io/gravitee/gateway/reactive/handlers/api/v4/DefaultApiReactorFactoryTest.java @@ -317,9 +317,9 @@ private List registerApiTemplateVariableProvider(List< TemplateVariableProviderFactory apiTemplateVariableProviderFactory = mock(ApiTemplateVariableProviderFactory.class); when(apiTemplateVariableProviderFactory.getTemplateVariableProviders()).thenReturn(providers); when(apiTemplateVariableProviderFactory.getTemplateVariableScope()).thenReturn(TemplateVariableScope.API); - lenient() - .when(applicationContext.getBeansOfType(TemplateVariableProviderFactory.class)) - .thenReturn(Map.of("apiTemplateVariableProviderFactory", apiTemplateVariableProviderFactory)); + String[] providersName = { "apiTemplateVariableProviderFactory" }; + lenient().when(applicationContext.getBeanNamesForType(TemplateVariableProviderFactory.class)).thenReturn(providersName); + lenient().when(applicationContext.getBean("apiTemplateVariableProviderFactory")).thenReturn(apiTemplateVariableProviderFactory); return providers; }