且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在spring bean中,是否可以有一种可以使用事务的关闭方法?

更新时间:2023-02-19 23:23:56

有趣的问题.我说您应该可以通过

Interesting Question. I'd say you should be able to do it by letting your bean implement SmartLifeCycle.

这样,如果您的int getPhase();方法返回Integer.MAX_VALUE,它将在ApplicationContext最终关闭时成为第一个被调用的对象.

That way, if your int getPhase(); method returns Integer.MAX_VALUE, it will be among the first to be called when the ApplicationContext finally shuts down.

参考: