spring-projects / spring-projects/spring-hateoas

Unable to resolve place holders in @RequestMapping

Open
#1,406 2 comments 0 reactions 0 assignees View on GitHub

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 :
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 ? :)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.