As documented in Bean.destroyMethod
:
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 theclose()
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’.
In other words, if you don’t specify destroyMethod
, but the bean has a public close()
or shutdown()
method, it will be automatically used as the destroy-method.
To disable this inference, use @Bean(destroyMethod = "")
.