0

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

Here are important configurations in web.xml:

Servlet object and servlet url mapping:

<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>

restServiceExporter-servlet.xml configurations:

<?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>

web.xml ContextConfigurationLocation:

<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>

Configurations in restServices.xml:

<?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>

When I carefully compared the stp.log here is what I found the difference:

Spring 4.2.7 stp.log:

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]

Spring 5.3.2 stp.log:

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.

Naveen
  • 1
  • 2
  • Do not longer use xml based configuration. Use java based configuration instead – Jens Jan 14 '22 at 09:32
  • Well considering the enterprise application what we use, its a quite a large effort to convert it into java based configuration. – Naveen Jan 14 '22 at 13:06
  • Did you modify your `web.xml` in the process? It should have a `ContextLoaderListener` which isn't clear from the snippets you posted. The logging changed from INFO to TRACE so that you don't see it anymore is logical as i doubt you have TRACE logging enabled. Finally I see nothing that should load the `restServices.xml` at least that isn't clear here and if anything loads it it should be the servlet **not** the root context. – M. Deinum Jan 31 '22 at 11:15
  • 1) web.xml has the ContextLoaderListner in the first place. 2) restServices.xml we are trying to scan all the Controller classes by specifying the package name. – Naveen Feb 01 '22 at 11:49

1 Answers1

0

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>

Earlier In Spring 4.2.7.RELEASE our dispatcher servlet xml looks like below:

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
  <property name="order" value="0" />
  <property name="detectHandlersInAncestorContexts" value="true" />
 </bean>
Naveen
  • 1
  • 2