title: Spring MVC : Ambiguous mapping found
body: <p>I couldn't understand why the following gives an ambiguous mapping.</p>
  
  <p>a. The controller class</p>
  
  <pre><code>@Controller
  @RequestMapping("/employees")
  public class EmployeeController {
  
  @Autowired
  private EmployeeService employeeService;
  
  @RequestMapping(value = "/new", method = RequestMethod.GET)
  public String get(Model model) {
      return "xx";
  }
  
  }
  </code></pre>
  
  <p><strong>Console output:</strong>    </p>
  
  <pre><code>java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'org.tutorial.spring.controller.EmployeeController#0' bean method 
  public java.lang.String org.tutorial.spring.controller.EmployeeController.get(org.springframework.ui.Model)
  to {[/employees/new],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'employeeController' bean method
  public java.lang.String org.tutorial.spring.controller.EmployeeController.get(org.springframework.ui.Model) mapped.    
  </code></pre>
  
  <p>It says method has already been mapped.
  How so?</p>
  
  <p>b. web.xml</p>
  
  <pre><code>&lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>c. spring.xml</p>
  
  <pre><code>&lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="org.tutorial.spring" /&gt;
  &lt;mvc:annotation-driven /&gt;
  &lt;bean class="org.tutorial.spring.controller.EmployeeController" /&gt;
  </code></pre>