Skip to content

Cannot build link using Spring-MVC and router functions dsl #1964

Open
@NoxFr

Description

@NoxFr

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 ?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions