Post migrating from Spring 4.2.7 to 5.3.2 none of REST API's of our application are triggering. For ex: every REST call I make I get the error in stp.log is:
No mapping for GET /application relative path/XXXX/YYYY.rest
<servlet>
<servlet-name>restServiceExporter</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<run-as>
<role-name>AllAuthenticated</role-name>
</run-as>
</servlet>
<servlet-mapping>
<servlet-name>restServiceExporter</servlet-name>
<url-pattern>*.rest</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>restServiceExporter</servlet-name>
<url-pattern>*.admin</url-pattern>
</servlet-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
</bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />
</list>
</property>
</bean>
<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean" />
</beans>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/cxf.xml,
classpath*:META-INF/<module-name>/applicationContextWeb.xml,
classpath*:META-INF/dataAccessContext-inContainer.xml,
classpath*:META-INF/<module-name>/applicationContextService.xml,
classpath*:META-INF/<module-name>/applicationContextWeb.xml,
</param-value>
</context-param>
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="<rest Controller package>" use-default-filters="false">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />
</context:component-scan>
</beans>
2022-01-11 02:09:59,402 main INFO web.context.ContextLoader Root WebApplicationContext: initialization started
2022-01-11 02:10:00,900 main INFO context.support.XmlWebApplicationContext Refreshing Root WebApplicationContext: startup date [Tue Jan 11 02:10:00 EST 2022]; root of context hierarchy
2022-01-11 02:10:02,069 main INFO factory.xml.XmlBeanDefinitionReader Loading XML bean definitions from ServletContext resource [/WEB-INF/cxf.xml]
2022-01-11 02:10:04,047 main INFO factory.xml.XmlBeanDefinitionReader Loading XML bean definitions from URL [jar:file:/C:/stp/app/webapps/ourApp/WEB-INF/lib/XYZ.jar!/META-INF/module-name/applicationContextWeb.xml]
2022-01-11 02:10:04,176 main INFO factory.xml.XmlBeanDefinitionReader Loading XML bean definitions from URL [jar:file:/C:/stp/app/webapps/ourApp/WEB-INF/lib/XYZ.jar!/META-INF/module-name/restServices.xml]
2022-01-11 02:20:50,506 main INFO web.context.ContextLoader Root WebApplicationContext: initialization started
After this line of log, I do not see any applicationcontext specific xml's are loaded.
Any lead on this issue, is really appreciated.
I was able to resolve this issue with Spring 5.2.19.RELEASE version rather than Spring5.3.2 and since we need to read all the applicationContext and restServices.xml files which are located in multiple jars, I had to add "DetectHandlerMethodsInAncestorContexts" property to RequestMappingHandlerMapping bean class as below:
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order"><value>98</value></property>
<property name="DetectHandlerMethodsInAncestorContexts" value="true" />
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" />
<property name="detectHandlersInAncestorContexts" value="true" />
</bean>