WebSphere Application Server 在其文档之一中有以下注释。我在耳朵级别拥有应用程序上下文,并使用 ClassPathXmlApplicationContext
,它是 AbstractApplicationContext
的子类。但不建议这样做。我有什么选择?我可以在耳朵层面利用哪些生命周期 Hook ?另外,请包括任何问题或经验教训。
The following scenarios are examples of Spring Framework scenarios to avoid:
registerShutdownHook
Avoid using the Spring Framework AbstractApplicationContext class and its subclasses. These classes include the public method registerShutdownHook, which creates a thread and registers it with the Java virtual machine (JVM) to run at shutdown to close the application context. As an alternative, an application can use the lifecycle notices that it receives from the application server container to call the close method explicitly on the application context.
最佳答案
我会使用 Singleton Session Bean (如果是 WebSphere 8+)或 Startup Beans (对于较旧的 Websphere 版本),如 related problem 中所述。 。
对于Singleton Session Beans
,您可以创建一个用@PreDestroy
注释的方法,它将 close AbstractApplicationContext 。
对于 Startup Beans
,您可以在 stop()
方法中执行相同的操作。
关于java - 应用服务器和 Spring 上下文加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13495854/