send command when handlers are registered

Hi,

I want to implement a service, which on startup should send Commands to the CommandGateway when it is started for the first time, but I have trouble with it, as I try doing it with a @PostConstruct method, but that is called before the CommandHandlers are registered resulting in a org.axonframework.commandhandling.NoHandlerForCommandException.

Is there a way to “wait” for the application to be done with handler registration before I start sending commands to the CommandGateway?

Kind regards,
Lars Karschen

Hi Lars,
I’ve done this before by implementing an ApplicationListener:

@Component
public class ApplicationStartup
        implements ApplicationListener<ApplicationReadyEvent> {

    /**
     * This event is executed as late as conceivably possible to indicate that
     * the application is ready to service requests.
     */
    @Override
    public void onApplicationEvent(final ApplicationReadyEvent event) {

        **//Your code here, and probably inject a CommandBus :)** 
    }
}

This is exactly what i need, thanks!

Kind regards,
Lars