0

I'm sorry this is a kind of duplicate question of this other one already asked by me: Spring MVC Rest: No mapping found for HTTP request with URI [/ecommerce-api/rest/checkout] in DispatcherServlet

But I'm getting mad, since the problem after while appears again. When everything seems to be working suddenly it stops :-(

I'm trying to build an API with SpringMVC, I'm developing using STS 3.3.0 and testing with the rest shell 1.2.1.

The command I'm issuing is:

get ecommerce-api/rest/checkout

and the error I got is:

2013-09-10 11:56:49,614 DEBUG [tomcat-http--9] servlet.DispatcherServlet (DispatcherServlet.java:823) - DispatcherServlet with name 'api-dispatcher' processing GET request for [/ecommerce-api/rest/checkout] 2013-09-10 11:56:49,615 DEBUG [tomcat-http--9] handler.AbstractHandlerMethodMapping (AbstractHandlerMethodMapping.java:220) - Looking up handler method for path /checkout 2013-09-10 11:56:49,615 DEBUG [tomcat-http--9] handler.AbstractHandlerMethodMapping (AbstractHandlerMethodMapping.java:230) - Did not find handler method for [/checkout] 2013-09-10 11:56:49,615 WARN [tomcat-http--9] servlet.DispatcherServlet (DispatcherServlet.java:1108) - No mapping found for HTTP request with URI [/ecommerce-api/rest/checkout] in DispatcherServlet with name 'api-dispatcher' 2013-09-10 11:56:49,615 DEBUG [tomcat-http--9] servlet.FrameworkServlet (FrameworkServlet.java:966) - Successfully completed request

Until yesterday everything was working absolutely fine, this morning I tried to add some more functionalities to my really basic controller and I got the above error.

What I tried without success:

1) reverting to last working version from git repositories

2) deploying the war package in a clean Tomcat install (trying to have avoid any possible issue related to Eclipse)

3) unpublishing the package from the vFabric within STS - cleaning its working dir - cleaning the project - deploying it again

I copy there my *.xml and java files, even if they seems to be ok since they worked since a couple of hours ago.

Any idea or suggestion will be really appreciated.

A frustrated developer (aka Alexio).

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/application-context.xml
    </param-value>
</context-param>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>

<servlet>
    <servlet-name>api-dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/api-dispatcher-servlet.xml</param-value>
    </init-param>
    <init-param>
        <param-name>debug</param-name>
        <param-value>6</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>api-dispatcher</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>


<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>


</web-app>

api-dispatcher.xml

<?xml version="1.0" encoding="UTF-8" ?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.fashionis.api.ecommerce.controller" />
    <context:annotation-config />
    <mvc:annotation-driven />

    <import resource="classpath:/ecommerce-services-beans.xml"/>

</beans:beans>

checkoutcontroller.java

@Controller
@RequestMapping("/checkout")
public class CheckoutController {

    private static final Logger logger = LoggerFactory.getLogger(CheckoutController.class);

        @RequestMapping(method = RequestMethod.GET)
    public @ResponseBody
    Checkout getRandomCheckout() {

        logger.debug("Before instantiating checkoutManager");
        @SuppressWarnings("resource")
        ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("ecommerce-services-beans.xml");
        CheckoutManager checkoutManager = ctx.getBean("checkoutManager", CheckoutManager.class);

        logger.debug("Before asking for checkout");

        Checkout checkout = checkoutManager
                .findById("514f2a8e20f7a78a1400001f");

        logger.debug("Checkout obtained. Con ID:" + checkout.getId());

        return checkout;
    }
}
Community
  • 1
  • 1
Alexio Cassani
  • 269
  • 2
  • 6
  • 19
  • Your `CheckoutController` is already wrong you should **never** create an applicationcontext to get a bean, for that use dependency injection. – M. Deinum Sep 10 '13 at 11:55
  • Thank you, it was just a basic controller to test integration from REST api to our back-end services. But I don't think this could be a cause of the mapping problem since it happens before the getRandomCheckout is done (and if I try to comment the whole implementation I still have the same problem) – Alexio Cassani Sep 10 '13 at 13:20
  • In your configuration you also have a duplicate RequestContextListener. Enable 'debug' logging for `org.springframework.web` package and when the application is starting the URL to method/controller mapping should be shown. If there is no mapping there is something wrongin your setup. – M. Deinum Sep 11 '13 at 07:49
  • I've removed the duplication in my config and also performed some debug during the application initialization and now it seems to be _robust_ (that's so say I've restarted many times and after changing a lot of stuff within my classes and everytime it worked). Thanks a lot! – Alexio Cassani Sep 12 '13 at 08:20
  • BTW I've also changed the bean initialization as you pointed in your first comment :-) – Alexio Cassani Sep 12 '13 at 08:20

0 Answers0