spring-projects / spring-projects/spring-hateoas
Unable to resolve place holders in @RequestMapping
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
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 :

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 ? :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/main/java/org/springframework/hateoas/server/core/PropertyResolvingMappingDiscoverer.java around line 90 and inspect why ContextLoader.getCurrentWebApplicationContext() is null under Spring Boot. Reproduce with spring-hateoas 1.2.1 and Spring Boot 2.4.0 using a @RequestMapping placeholder and RepresentationModel response. Done means the placeholder resolves instead of producing the reported expansion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100