Skip to content

Kediatr suspend handler calls break Spring AOP proxies (e.g., @Transactional) #476

@An2An96

Description

@An2An96

When using Kediatr with Kotlin suspend handlers in combination with Spring AOP annotations such as @transactional, the framework throws an exception similar to:

AOP configuration seems to be invalid: tried calling method [public java.lang.Object com.example.handlers.CreateCatalogCommandHandler.handle(com.trendyol.kediatr.Request, kotlin.coroutines.Continuation)] on target [com.example.handlers.CreateCatalogCommandHandler@123456]

Observed behavior:
• Direct injection of the same handler into a Spring controller works correctly — @transactional works as expected.
• Calling the handler via Kediatr triggers an AOP configuration exception.
• The root cause appears to be that Kediatr uses reflection to call suspend handlers, which bypasses Spring proxies, making @transactional and other aspects fail.

Minimal example:

@Component
class CreateCatalogCommandHandler(
    private val repository: CatalogRepository
): CommandHandler<CreateCatalogCommand, CatalogId> {

    @Transactional
    override suspend fun handle(command: CreateCatalogCommand): CatalogId {
        // transactional code here
    }
}

Calling this handler via Kediatr leads to the AOP exception, but calling it directly works:

@RestController
class CatalogController(
    private val handler: CreateCatalogCommandHandler
) {
    @PostMapping("/catalog")
    fun create(@RequestBody cmd: CreateCatalogCommand): CatalogId {
        return handler.handle(cmd) // works fine
    }
}

Motivation / Use Case:

Many Spring applications rely on @transactional to manage database consistency. Kotlin suspend functions are commonly used in modern apps. Currently, Kediatr does not correctly integrate with Spring AOP for suspend handlers, which prevents the use of transactional or other AOP-based cross-cutting concerns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions