title: Overload Controller Method in Java Spring
body: <p>I have a controller that needs to behave differently with different URL parameters. Something like this:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET)
  public A getA(@RequestParam int id, @RequestParam String query) {
      ...
  }
  
  
  @RequestMapping(method = RequestMethod.GET)
  public A getA(@RequestParam int id) {
      ...
  }
  </code></pre>
  
  <p>But this doesn't seem to work, I get the following exception:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping found. Cannot map '[controller name]' bean method 
  </code></pre>
  
  <p>Is there a way that the application chooses the method depending on the URL params?</p>