From 2b95cd43e7f44add122c6cddd294dc733914e6be Mon Sep 17 00:00:00 2001 From: srishti Date: Wed, 14 Feb 2024 16:13:25 +0100 Subject: [PATCH] ## Specify Requesthandler bean name for spring boor 2.7 version api's --- .../AbstractRequestPathMethodService.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/commons-web/src/main/java/eu/europeana/api/commons/web/service/AbstractRequestPathMethodService.java b/commons-web/src/main/java/eu/europeana/api/commons/web/service/AbstractRequestPathMethodService.java index 43fa4224..e93c0534 100644 --- a/commons-web/src/main/java/eu/europeana/api/commons/web/service/AbstractRequestPathMethodService.java +++ b/commons-web/src/main/java/eu/europeana/api/commons/web/service/AbstractRequestPathMethodService.java @@ -39,13 +39,25 @@ protected AbstractRequestPathMethodService( this.applicationContext = applicationContext; } - /** Populate request url pattern - request methods map */ + /** + * For Services or APIs using spring boot version > 2.7.x + * Spring Boot 2.7 no longer defines MVC’s main requestMappingHandlerMapping bean as @Primary bean. + * In the unlikely event that we are injecting RequestMappingHandlerMapping bean, we need to be specific + * about the bean name. + * We need the bean of name - "requestMappingHandlerMapping" + * + * @see Dcoumentation + * + * Otherwise we get - org.springframework.beans.factory.NoUniqueBeanDefinitionException: + * No qualifying bean of type 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping' + * available: expected single matching bean but found 2: requestMappingHandlerMapping,controllerEndpointHandlerMapping + * + * Populate request url pattern - request methods map */ @Override public void afterPropertiesSet() { RequestMappingHandlerMapping mapping = - applicationContext.getBean(RequestMappingHandlerMapping.class); + applicationContext.getBean("requestMappingHandlerMapping", RequestMappingHandlerMapping.class); Map handlerMethods = mapping.getHandlerMethods(); - for (RequestMappingInfo info : handlerMethods.keySet()) { PatternsRequestCondition p = info.getPatternsCondition();