Skip to content

Commit

Permalink
## Specify Requesthandler bean name for spring boor 2.7 version api's
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Feb 14, 2024
1 parent 3b7a7dd commit 2b95cd4
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#spring-mvcs-requestmappinghandlermapping-is-no-longer-primary">Dcoumentation</a>
*
* 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<RequestMappingInfo, HandlerMethod> handlerMethods = mapping.getHandlerMethods();

for (RequestMappingInfo info : handlerMethods.keySet()) {
PatternsRequestCondition p = info.getPatternsCondition();

Expand Down

0 comments on commit 2b95cd4

Please sign in to comment.