java - 应用服务器和 Spring 上下文加载

标签 java spring jakarta-ee websphere

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/

相关文章:

java - Spring Config 将字符串映射到对象

spring - 添加Spring安全标签库

java - ArrayList运行时错误

Java POI FormulaEvaluator 给出意外的浮点值

java - 使用 Spring MVC 显示数据库数据时出错

java - 将动态 JSON 值解析为 Java 对象

java - 连接 Android 和 Java EE 服务器

java - 在 glassfish 中更改 JSP 编译器版本

java - 在spring计划任务中触发python脚本

java - 平衡括号问题的优化解