[Spring Boot] AsynchronousCommandBus.shutdown()

In the axon “Command Dispatching” documentation (https://docs.axonframework.org/v/3.1/part3/command-dispatching.html#asynchronouscommandbus) there is some advice to shut down the bus when stopping the application. I came up with a solution, but it seems a little contrived and was hoping someone could steer me in the right direction.

Below is a snippet from my axon configuration class. I have defined a custom extension of AsynchronousCommandBus with a @PreDestroy annotated method which I configure as the command bus:

Hi,

one the @Bean annotation, you can also specify a destroyMethod. No need to override it, just mention @Bean(destroyMethod=“shutdown”) on top of the commandBus() method.

However, according to the documentation on @Bean, methods named “close” and “shutdown” are invoked automatically when detected on a bean:
From the Javadoc:
As a convenience to the user, the container will attempt to infer a destroy method against an object returned from the @Bean method. For example, given an @Bean method returning an Apache Commons DBCP BasicDataSource, the container will notice the close() method available on that object and automatically register it as the destroyMethod. This ‘destroy method inference’ is currently limited to detecting only public, no-arg methods named ‘close’ or ‘shutdown’. The method may be declared at any level of the inheritance hierarchy and will be detected regardless of the return type of the @Bean method (i.e., detection occurs reflectively against the bean instance itself at creation time).

Cheers,

Allard