spring-hateoas icon indicating copy to clipboard operation
spring-hateoas copied to clipboard

Unable to resolve place holders in @RequestMapping

Open adriendengreville opened this issue 4 years ago • 2 comments
trafficstars

Using spring-hateoas:1.2.1 with Spring Boot 2.4.0:

When a REST controller class annotated with @RequestMapping("${some-variable}/resources") returns a resource extending RepresentationModel, I get the following error :

{
"label": "uncatched exception",
"detailMessage": "Not enough variable values available to expand 'some-variable'",
"statusCode": 500
}

I pinned the issue to this suspect line in the core library : https://github.com/spring-projects/spring-hateoas/blob/646e73c8c5ca5f1302bd6722e0ad338be0309fc9/src/main/java/org/springframework/hateoas/server/core/PropertyResolvingMappingDiscoverer.java#L90

From what I could read, ContextLoader.getCurrentWebApplicationContext() doesn't return the expected context when using Spring Boot, and it's actually returning null when I place a breakpoint there : image You can see (L.92) that the resolvePlaceholders method won't be called, explaining my error since the raw string is passed on.

Any idea on how we could fix this ? :)

adriendengreville avatar Dec 08 '20 16:12 adriendengreville

I only searched is the open issues for duplicate, my bad, and this has already been partially fixed: https://github.com/spring-projects/spring-hateoas/issues/220 PR https://github.com/spring-projects/spring-hateoas/pull/1375 (not yet merged) seems to fix this issue, though !

adriendengreville avatar Dec 08 '20 16:12 adriendengreville

I also ran into this issue. Is there any chance to see the linked PR merged? Or does something need to be improved on it?

Arpic avatar Jul 18 '22 14:07 Arpic