Spring: How to cleanly terminate prototype-scoped beans?

前端 未结 2 670
鱼传尺愫
鱼传尺愫 2021-01-04 07:35

According to Spring documentation when a bean is scoped as \"prototype\" spring does not manage the complete lifecycle of its objects. More specifically the destruction life

相关标签:
2条回答
  • 2021-01-04 07:54

    The only clean way to terminate prototype-scoped bean is to explicitly call some of its "destroy"-methods to dispose resources. You can also use Phantom References. Here is more info on different types of references.

    0 讨论(0)
  • 2021-01-04 08:06

    What you're looking for is the DestructionAwareBeanPostProcessor, it's a sub-interface of BeanPostProcessor.

    You could create a new implementation of that interface yourself, or use one of its implementing classes, like CommonAnnotationBeanProcessor.

    0 讨论(0)
提交回复
热议问题