Spring-hateoas: Add support for @GetMapping, @PostMapping etc. introduced in Spring 4.3 in ControllerLinkBuilder

Created on 26 Jul 2016  Â·  6Comments  Â·  Source: spring-projects/spring-hateoas

Now if controller has @GetMapping("/some/path/{id}") then this exception occurs:

java.lang.IllegalArgumentException: 'uriTemplate' must not be null
    at org.springframework.util.Assert.hasText(Assert.java:168) ~[spring-core-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.web.util.UriTemplate.<init>(UriTemplate.java:61) ~[spring-web-4.3.1.RELEASE.jar:4.3.1.RELEASE]
    at org.springframework.hateoas.mvc.ControllerLinkBuilderFactory.linkTo(ControllerLinkBuilderFactory.java:134) ~[spring-hateoas-0.20.0.RELEASE.jar:na]
    at org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo(ControllerLinkBuilder.java:172) ~[spring-hateoas-0.20.0.RELEASE.jar:na]

If I change this mapping to @RequestMapping(path = "/some/path/{id}", method = RequestMethod.GET) then all works fine.

Versions used: spring-boot-starter-hateoas 1.4.0.RC1, spring-hateaos 0.20.0.RELEASE, spring 4.3.1.RELEASE.

Most helpful comment

Has there been any progress on this issue?

I've just experienced the same problem with changing my controller method annotation from @RequestMapping(value = "/{id}", method = RequestMethod.GET) which works by including the id in the links, to @GetMapping("/{id}") which breaks the links by _not_ including the id in the links.

I expect that these two annotation should be equivalent for my usage.

Thanks, in advance.

All 6 comments

Looks like this will require us to upgrade to at least Spring 4.2 as only that version contains the code necessary to lookup merged annotations.

Has there been any progress on this issue?

I've just experienced the same problem with changing my controller method annotation from @RequestMapping(value = "/{id}", method = RequestMethod.GET) which works by including the id in the links, to @GetMapping("/{id}") which breaks the links by _not_ including the id in the links.

I expect that these two annotation should be equivalent for my usage.

Thanks, in advance.

@olivergierke any idea when we have corrected mappings available?

There's gonna be an Ingalls RC1 for downstream Spring Data REST for which we probably want to have a fresh Spring HATEOAS release, too.

I guess the fix is pretty trivial as all we need to adapt is the way we resolve the mappings in AnnotationMappingDiscoverer, i.e. use the new Spring 4.3 API to detect the attributes (AnnotatedElementUtils.findMergedAnnotation(…)). Wouldn't mind to see a PR for this.

Wait, I see there already is one #497.

Thanks.

2016-10-27 14:43 GMT+02:00 Oliver Gierke [email protected]:

Wait, I see there already is one #497
https://github.com/spring-projects/spring-hateoas/pull/497.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/spring-projects/spring-hateoas/issues/471#issuecomment-256630190,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACGGYf4syPT3MD8wpidKsTAxauJdwhHYks5q4JxygaJpZM4JVF5_
.

Patryk Rogosch

Mob: + 48 501-256-542

Was this page helpful?
0 / 5 - 0 ratings