Repository navigation
Closed
Description
Oliver Drotbohm opened SPR-14182 and commented
Let's start with the reproducing sample first.
$ 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
The server produces the following exception:
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]
…
I was caught by surprise to see that as the two methods mentioned — RepositoryEntityController.headCollectionResource(…) and RepositoryEntityController. getCollectionResource(…) 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).
Affects: 4.3 RC1
Attachments:
- Bildschirmfoto 2016-04-16 um 14.35.55.PNG (182.76 kB)
Issue Links:
- Spring should have default support for OPTIONS, HEAD and Allow [SPR-13130] #17721 Spring should have default support for OPTIONS, HEAD and Allow
- Regression: IllegalStateException: Ambiguous handler methods is thrown for explicit HEAD mapping [SPR-17593] #22125 Regression: IllegalStateException: Ambiguous handler methods is thrown for explicit HEAD mapping
Activity
spring-projects-issues commentedon Apr 16, 2016
Oliver Drotbohm commented
Added a screenshot showing the detected mappings in the Eclipse debugger. Note that the HTTP method mapping is reported to be
HEADwhere it actually is declared asGETin code.spring-projects-issues commentedon Apr 17, 2016
Juergen Hoeller commented
Rossen Stoyanchev, this looks like a side effect of our default HEAD handling against GET methods. While we treat it right invocation-wise if a dedicated HEAD mapping exists, we seem to get confused in the mapping registration phase when the mappings just differ in GET vs HEAD.
spring-projects-issues commentedon Apr 17, 2016
Rossen Stoyanchev commented
This should be fixed now.