title: Spring MVC Controller not resolving URI
body: <p>This is a similar question to those that have been asked before, but still different, and I simply can't figure it out.</p>
  
  <p>I have a controller for a REST webservice implemented with MVC which should be handling requests for the path '/users/contacts', the problem is that in my client test app, when I try to hit that path I get:</p>
  
  <pre><code>No mapping found for HTTP request with URI /users/users/contacts in DispatcherServlet with name 'webservice'
  </code></pre>
  
  <p>Again, in my client test app, when I change the request path to something like '/WHATEVERusers/contacts', I'll get an error that it can't resolve '/WHATEVERusers/contacts'</p>
  
  <p>I don't know why when I try to hit a path handled by a controller it get's mangled, but when I request some garbage path, it doesn't.</p>
  
  <p>I don't have the code in front of me, but will be able to answer questions when I get home.</p>
  
  <p>Here's code from my test client:</p>
  
  <pre><code>private static void TestGetContacts()
  {
      UserCreateRequest request = new UserCreateRequest();
  
      Gson gson = new Gson();
  
      try
  
      {
          HttpClient client = new DefaultHttpClient();
  
          StringEntity string  = new StringEntity(gson.toJson(request), HTTP.UTF_8);
          string.setContentType("application/json");
  
          URI uri = URIUtils.createURI("http", "localhost", 8888, "/users/contacts", null, null);
  
          HttpPost post = new HttpPost(uri);
          post.setEntity(string);
  
          client.execute(post);
      }
      catch(Exception ex)
      {
          System.out.println(ex.getMessage());
      }
  }
  </code></pre>
  
  <p>Here's my controller class:</p>
  
  <pre><code>@Controller
  @RequestMapping("/users/contacts")
  public class UserContactService
  {
  private @Autowired ApplicationContext appContext;
  
  @RequestMapping(method=RequestMethod.POST, consumes="application/json", produces="application/json")
  public GetContactsResponse GetContacts(@RequestBody UserCreateRequest request)
  {
      GetContactsResponse response = new GetContactsResponse();
  
      return response;
  }
  }
  </code></pre>
  
  <p>Here's my servlet config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
  xmlns:context="http://www.springframework.org/schema/context"
      xmlns:oxm="http://www.springframework.org/schema/oxm"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
              http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
              http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"&gt;
  
  &lt;!--
      - The controllers are autodetected POJOs labeled with the @Controller annotation.
  --&gt;
  &lt;context:component-scan base-package="com.impersonal.server.restservice.users"/&gt;                
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;list&gt;
              &lt;ref bean="jsonConverter" /&gt;
              &lt;!-- 
              &lt;ref bean="marshallingConverter" /&gt;
              &lt;ref bean="atomConverter" /&gt;
              --&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
      &lt;property name="supportedMediaTypes" value="application/json" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here's my web config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5"&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;classpath:/**/applicationContext.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;webservice&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;webservice&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Update:</strong>
  My requests are handled in my controller, but after the request is handled, the server prints out that it couldn't resolve /users/users/contacts.  For some reason another request is getting to DispsatcherServlet, and I don't know why..</p>
  
  <p>Thanks,
  Mark</p>