gargi258
gargi258

Reputation: 839

Axon 3 not found handler

I'm beginner with Java. I would configure my handler only for working and processing command. At this moment I receive Exception No handler was subscribed to command [com.capgemini.books.CreateBook].

My code looks like:

@Configuration
public class ControllerConfig {
    @Bean
    public CommandBus commandBus() {
        return new SimpleCommandBus();
    }
}

public class CreateBookHandler {
    public CreateBookHandler() { }

    @CommandHandler
    public void handle(CreateBook command) {
       Book newBook = new Book(1001L, "anonymous", command.bookTitle());
    }
}

Upvotes: 2

Views: 680

Answers (1)

Steven
Steven

Reputation: 7275

hope I can help you with this :-)

Taking you're running your application through Spring Boot and that you're using the axon-spring-boot-starter dependency to wire everything automatically, then I know what you're missing. The CreateBookHandler is not a Spring Bean, hence the auto wiring set up of Axon doesn't notice it as a bean and thus cannot find the @CommandHandler annotated function on it.

Additionally though, I'd typically put my command handling functions directly on the aggregate rather then in a separate component within my setup. Reason for that is because commands are most of the times in the context of a single aggregate, so why not let the aggregate itself handle it?

Hope this helps you out!

Upvotes: 4

Related Questions