Skip to content

Web handlers don't support Kotlin extensions #31876

Closed
@Raphael-Kleindienst

Description

Hi.

while migrating from spring-boot 3.1.5 -> 3.2.0 all the Exception-handlers stopped working in our project. It turns out that functions can't be declared as kotlin extension functions anymore. Here's a code sample that works as expected for spring-boot-3.1.5 and not for spring-boot-3.2.0

class DemoApplication

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

@RestController
class MyController{

    @GetMapping("/test")
    fun test() : String {throw CustomException()}

    @ExceptionHandler(CustomException::class)
    fun CustomException.handle(): ResponseEntity<Any>{
        return ResponseEntity.status(HttpStatus.I_AM_A_TEAPOT.value()).build()
    }
}

class CustomException : Throwable()

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)theme: kotlinAn issue related to Kotlin supporttype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions