I have an application that has a datasource. Everytime I undeploy the application from the manager GUI the datasources are being closed. When I try to redeploy, the dataso
This isn't specific to Spring Boot, it's standard Spring behaviour.
By default, Spring will infer a bean's destroy method. From the javadoc for @Bean:
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 DBCPBasicDataSource
, the container will notice theclose()
method available on that object and automatically register it as thedestroyMethod
. This 'destroy method inference' is currently limited to detecting only public, no-arg methods named 'close' or 'shutdown'.
The javadoc goes on to describe how to disable this behaviour:
To disable destroy method inference for a particular
@Bean
, specify an empty string as the value, e.g.@Bean(destroyMethod="")
You need to update your dataSource()
method:
@Bean(destroyMethod="")
public DataSource dataSource() {
return new JndiDataSourceLookup().getDataSource("com.datasource.CONSUMER");
}