commandhandler static factory methods

In the webinar for 3.2 it was mentioned, that a feature of 3.1 was the support of commandHandler factory methods. I couldn’t find an example and was not able to get it work.
I assumed I would do something like

class AccountAggregate() {

  companion object : KLogging() {
    fun create(c: Command.CreateAccount): AccountAggregate {
      return AccountAggregate()

  lateinit var id: String
  var balance: Int = 0

  fun on(e: Event.AccountCreated) {
    id =
    balance = e.balance

but I get No handler was subscribed to command [org.springbootcamp.axon.querybus.Command$CreateAccount]

What did I get wrong?

Hi Jan,

Generally when working in Kotlin, to get a companion object method recognized as a static class method from a Java perspective, you need the @JvmStatic annotation:

The code for this feature uses a Modifier.isStatic call to check whether a method qualifies as a factory method, so you would need @JvmStatic to make that work.

Could you try again with this annotation?

Kind regards,

wow, great, thanks very much! Works.