java 在 J2SE 中“关闭”spring 上下文的正确方法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2295974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:29:41  来源:igfitidea点击:

Proper way of "shutdown" a spring context in J2SE

springjava

提问by X-Blaster

I'm currently experiencing problems with a JPATransactionManager in a J2SE application.

我目前在 J2SE 应用程序中遇到 JPATransactionManager 问题。

The latest request was not properly saved in the database (surely a problem of cache).

最新的请求没有正确保存在数据库中(肯定是缓存的问题)。

This seems to be normal because the exit of the program does not seem to "cleanly" exit all Bean of the spring application context.

这似乎是正常的,因为程序的退出似乎并没有“干净地”退出spring应用程序上下文的所有Bean。

Do you know if there's a method of a clean shutdown a Spring context before exiting ?

你知道在退出之前是否有一种干净关闭 Spring 上下文的方法吗?

Thank you in advance.

先感谢您。

采纳答案by DJ.

Checkout Spring Referencemanual on this topic.

请查看有关此主题的Spring 参考手册。

Basically you need to call registerShutdownHook()on the application context.

基本上你需要调用registerShutdownHook()应用程序上下文。