How does Lifecycle interface work in Spring? What are “top-level singleton beans”?

前端 未结 5 1615
無奈伤痛
無奈伤痛 2021-02-07 05:13

It is said in Spring javadoc, that \"Note that the Lifecycle interface is only supported on top-level singleton beans.\" Here URL

My LifecycleBeanTest.xml d

5条回答
  •  庸人自扰
    2021-02-07 05:53

    What about using SmartLifecycle? Seems like it provides all necessary functionality.

    There is method public void stop(Runnable contextStopping) {}. And you can continue app context closing by executing passed in contextStopping in time you want.

    In my environment all works fine even on J-UNIT, of course by running them with SpringJUnit4ClassRunner.

提交回复
热议问题