spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
921 stars 563 forks source link

Add Coroutines support for repository event handler #2427

Open sbont opened 2 weeks ago

sbont commented 2 weeks ago

When implementing a repository event handler in Kotlin, marking it as suspend fun causes an IllegalArgumentAxception: "wrong number of arguments". After some digging I found that a suspending function compiles to method expecting a kotlin.coroutines.Continuation as second parameter, and it seems to be unable to resolve this.

@Component
@RepositoryEventHandler(MyEntity::class)
class MyEntityEventHandler() {
    @HandleBeforeDelete
    suspend fun handleMyEntityDelete(value: MyEntity) {
//        logic
    }
}
mp911de commented 2 weeks ago

See also https://github.com/spring-projects/spring-framework/issues/28343