java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}

Spring JIRA | Oliver Gierke | 8 months ago
  1. 0

    Let's start with the reproducing sample first. {noformat} $ git clone https://github.com/spring-projects/spring-data-examples $ cd spring-data-examples/rest/starbucks $ mvn spring-boot:run $ curl -v -X HEAD http://localhost:8080/api/stores > HEAD /api/stores HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 500 Internal Server Error < Server: Apache-Coyote/1.1 < Content-Type: application/json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Sat, 16 Apr 2016 12:37:59 GMT < Connection: close {noformat} The server produces the following exception: {noformat} java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException} at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361) ~[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1] at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] at org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] … {noformat} I was caught by surprise to see that as the two methods mentioned — [{{RepositoryEntityController.headCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L160] and [{{RepositoryEntityController. getCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L193] are considered ambiguous as they actually declare request mappings for different HTTP methods. {{getCollectionResource}} clearly maps to {{GET}}, not {{HEAD}}. On Spring 4.2 this works as expected as you can see by downgrading the example to Spring Boot 1.4.0.M1 (by tweaking the version number of the Boot parent in the root project's POM).

    Spring JIRA | 8 months ago | Oliver Gierke
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}
  2. 0

    Let's start with the reproducing sample first. {noformat} $ git clone https://github.com/spring-projects/spring-data-examples $ cd spring-data-examples/rest/starbucks $ mvn spring-boot:run $ curl -v -X HEAD http://localhost:8080/api/stores > HEAD /api/stores HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.43.0 > Accept: */* > < HTTP/1.1 500 Internal Server Error < Server: Apache-Coyote/1.1 < Content-Type: application/json;charset=UTF-8 < Transfer-Encoding: chunked < Date: Sat, 16 Apr 2016 12:37:59 GMT < Connection: close {noformat} The server produces the following exception: {noformat} java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException} at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361) ~[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1] at org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] at org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91) ~[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na] … {noformat} I was caught by surprise to see that as the two methods mentioned — [{{RepositoryEntityController.headCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L160] and [{{RepositoryEntityController. getCollectionResource(…)}}|https://github.com/spring-projects/spring-data-rest/blob/2.5.1.RELEASE/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/RepositoryEntityController.java#L193] are considered ambiguous as they actually declare request mappings for different HTTP methods. {{getCollectionResource}} clearly maps to {{GET}}, not {{HEAD}}. On Spring 4.2 this works as expected as you can see by downgrading the example to Spring Boot 1.4.0.M1 (by tweaking the version number of the Boot parent in the root project's POM).

    Spring JIRA | 8 months ago | Oliver Gierke
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}
  3. 0

    Handling ambiguous handler methods mapped in REST application with Spring

    Stack Overflow | 10 months ago | mikezang
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/brand/1': {public java.util.List com.zangland.controller.BrandController.getBrand(java.lang.String), public com.zangland.entity.Brand com.zangland.controller.BrandController.getBrand(java.lang.Integer)}
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    "Ambiguous handler methods mapped for HTTP path" exception in spring MVC when submitting the form a third time

    Stack Overflow | 6 months ago | jayjaypg22
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8081/bus/topologie': {public java.lang.String fr.cnamts.navigo.web.TopologieController.updateNaturesPost(fr.cnamts.navigo.domain.Topologie,org.springframework.ui.Model) throws java.io.IOException, public java.lang.String fr.cnamts.navigo.web.TopologieController.genererClePost(fr.cnamts.navigo.domain.Topologie,org.springframework.ui.Model) throws java.io.IOException}
  6. 0

    Spring : Ambiguous handler methods mapped for HTTP path

    Stack Overflow | 7 months ago | jayjaypg22
    java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path 'http://localhost:8081/bus/topologie': {public java.lang.String fr.cnamts.navigo.web.TopologieController.genererCle(fr.cnamts.navigo.domain.Topologie,org.springframework.ui.Model) throws java.io.IOException, public java.lang.String fr.cnamts.navigo.web.TopologieController.updateNatures(fr.cnamts.navigo.domain.Topologie,org.springframework.ui.Model) throws java.io.IOException}

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Ambiguous handler methods mapped for HTTP path 'http://localhost:8080/api/stores': {public org.springframework.http.ResponseEntity org.springframework.data.rest.webmvc.RepositoryEntityController.headCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable) throws org.springframework.web.HttpRequestMethodNotSupportedException, public org.springframework.hateoas.Resources org.springframework.data.rest.webmvc.RepositoryEntityController.getCollectionResource(org.springframework.data.rest.webmvc.RootResourceInformation,org.springframework.data.rest.webmvc.support.DefaultedPageable,org.springframework.data.domain.Sort,org.springframework.data.rest.webmvc.PersistentEntityResourceAssembler) throws org.springframework.data.rest.webmvc.ResourceNotFoundException,org.springframework.web.HttpRequestMethodNotSupportedException}

      at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod()
    2. Spring MVC
      AbstractHandlerMethodMapping.lookupHandlerMethod
      1. org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:361)[spring-webmvc-4.3.0.RC1.jar:4.3.0.RC1]
      1 frame
    3. Spring Data REST - WebMVC
      RepositoryRestHandlerMapping.lookupHandlerMethod
      1. org.springframework.data.rest.webmvc.BasePathAwareHandlerMapping.lookupHandlerMethod(BasePathAwareHandlerMapping.java:110)[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na]
      2. org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.lookupHandlerMethod(RepositoryRestHandlerMapping.java:91)[spring-data-rest-webmvc-2.5.1.RELEASE.jar:na]
      2 frames