![](/img/trans.png)
[英]Maven EAR plugin: Generated EAR file does not contain WAR or EJB or RAR modules
[英]PayaraMicro does not call @PreDestroy on EJB or ApplicationScoped
我正在將一個 WAR 應用程序從 PayaraServer 遷移到 Payara Micro 以減少 RAM 使用量。
我只是意識到在使用 CTRL+C 停止實例時不會調用 EJB 上的 @PreDestroy。
是否有正確的方法可以正確關閉 payaramicro 實例,因為我想執行一些操作。
感謝您的回答!
或者要停用 Payara Server 中的哪些服務以使用與 PayaraMicro 一樣多的 RAM?
我使用的是 5.183 版本,我也嘗試了 5.192。
你用的是哪種EJB? 在我看來,它應該適用於@Singleton
和@Stateless
。 我不確定 Payara Micro 是如何支持其他 EJB 的。
但是,由於 Payara Micro 支持 Java EE Web Profile 並且您無論如何都在使用 Web 應用程序,因此我建議使用@WebListener
來獲取生命周期事件的通知。
它可以實現如下:
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
// do needed setup work here
}
@Override
public void contextDestroyed(ServletContextEvent event) {
// do your cleanup actions here
}
}
只需將此類添加到您的 WAR 文件中即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.