Why does Datasources close on Tomcat 7 undeploy with Spring Boot

后端 未结 1 1619
抹茶落季
抹茶落季 2020-12-16 04:04

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

相关标签:
1条回答
  • 2020-12-16 04:21

    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 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 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");
    }  
    
    0 讨论(0)
提交回复
热议问题