3

I am trying to develop a test REST application, by using the tutorial from here. I am deploying it as a war, by including war in my pom, and have built the application with no errors. When it comes to opening the URL, localhost:8080/gs-rest-service/rest/greeting I am getting a 404 error - more specifically a No mapping found for HTTP request with URI [/gs-rest-service/rest/greeting] in DispatcherServlet with name 'mvc-dispatcher'. I can't seem to see what is wrong, I have checked that my context root is set to gs-rest-service, and my GreetingController class looks like this:

package hello;

import java.util.concurrent.atomic.AtomicLong;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class GreetingController {

private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@RequestMapping("/greeting")
public @ResponseBody Greeting greeting(
        @RequestParam(value="name", required=false, defaultValue="World") String name) {
    return new Greeting(counter.incrementAndGet(),
                        String.format(template, name));
}

}

Here is my web.xml:

<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Spring Web MVC Application</display-name>

<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>

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

And here is my mvc-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="home" />

<mvc:annotation-driven /> 
</beans>

This is my project layout:

Would anyone be able to help me identify the issue here?

10
  • Please post your startup logs. Commented Nov 27, 2013 at 14:58
  • possible duplicate of Spring RESTful Service as a WAR instead of JAR in Tomcat Commented Nov 27, 2013 at 14:59
  • @SotiriosDelimanolis Where are the logs located? Commented Nov 27, 2013 at 15:03
  • The same place you found No mapping found for HTTP request with URI [/gs-rest-service/rest/greeting] in DispatcherServlet with name 'mvc-dispatcher'. Commented Nov 27, 2013 at 15:09
  • Shouldn't the service method be annotated with a \@GET, \@POST, etc ? AFAIK, you have not associated a HTTP method with your service. Commented Nov 27, 2013 at 15:13

1 Answer 1

1

You didn't specify the contextConfig location

  <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>

param-value is missing. Please give the location of the mvc-dispatcher-servlet.xml and try again. hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

Would the location be mvc-servlet-dispatcher?
it would be your mvc-dispatcher-servlet.xml
Ah just seen this, will try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.