java - Spring 芯。默认@Bean 销毁方法

标签 java spring release

我有自己的 bean :

@Bean
public MyBean myBean(){...

按照 spring 文档发布自己的资源我应该指定 destroyMethod。如果没有直接指定 destroyMethod,我还没有找到 spring 调用的任何默认销毁方法。

我用过

@Bean(destroyMethod = "close")
public MyBean myBean(){...

但是如果默认值有值的话,考虑不直接指定destroy方法的可能性。


spring 会默认尝试 destroycloserelease 之类的东西吗? 如果spring默认尝试一些方法来释放资源-哪些?

最佳答案

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 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'.

也就是说,如果你没有指定destroyMethod,但是bean有一个公共(public)的close()或者shutdown()方法, 它将自动用作销毁方法。

要禁用此推理,请使用 @Bean(destroyMethod = "")

关于java - Spring 芯。默认@Bean 销毁方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44756872/

相关文章:

java.net.UnknownHostException : Unable to resolve host "<url>": No address associated with hostname and End of input at character 0 of

java - 如何使用java在jsp选择标签中显示数据库中的完整表值

Java - 此递归中的操作顺序是什么?

eclipse - Tomcat 在 RUN 模式下启动但在 Debug模式下它永远挂起有什么问题?

java - Spring Prototype 作用域和 CDI 依赖作用域有什么区别?

java - Jersey 工厂尝试创建 @Context 变量两次

android - 获取要发布的 key 哈希

python 或 pyqt - 检查鼠标按钮的点击状态

仅发布版本中的 C# 应用程序问题

java - BufferedWriter 类的 writeLine 方法