spring-projects / spring-projects/spring-hateoas
Cannot build link using Spring-MVC and router functions dsl
@odrotbohm is already working on this.
Since May 3, 2023.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
Trying to add spring-hateoas in a Spring-Mvc / Kotlin / router functions DSL context.
Constructing link with :
fun Survey.toDto(): SurveyDto {
return SurveyDto(
id = id,
description = description,
questions = questions.map { it.toDto() },
tags = tags.map { it.toDto() },
state = state.name,
createdAt = createdAt,
updatedAt = updatedAt
).add(SurveyHandler::class) {
linkTo { getSurvey(id.toString()) } withRel SELF
}
}
With SurveryService
@Component
class SurveyHandler(private val surveyService: SurveyService) {
private val logger = KotlinLogging.logger {}
fun getSurvey(id: String): SurveyDto {
logger.info { "Calling GET survey with id: $id" }
return surveyService.findSurvey(UUID.fromString(id)).toDto()
}
And Routing
@Configuration
class RoutesConfiguration(private val surveyHandler: SurveyHandler) {
@Bean
fun surveyRoutes() = router {
"/v1/admin/survey".nest {
GET("/{id}") {
ok().body(surveyHandler.getSurvey(it.pathVariable("id")))
}
}
onError<Exception>(::handleExceptions)
}
}
Throws exception
java.lang.IllegalArgumentException: No mapping found for public com.liksi.questionr.server.survey.dto.SurveyDto com.liksi.questionr.server.survey.handler.SurveyHandler.getSurvey(java.lang.String)!
As seen here it seems to only handle @RequestMapping annotated method :
https://github.com/spring-projects/spring-hateoas/blob/main/src/main/java/org/springframework/hateoas/server/core/SpringAffordanceBuilder.java
Am i missing something ?
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.
Assessment
This issue has not been assessed yet.