我有一个使用JSF 1.2和Servlets 2.3以及Seam 2.2.0的JSF应用程序。我希望每次应用程序关闭时都运行一种备份。我尝试过像这样使用ServletContextListener:
public class ApplicationStartupAction implements ServletContextListener {
@In
FormActionImpl formAction;
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("Context destroyed");
formAction.migrateForms();
}
public void contextInitialized(ServletContextEvent arg0) {
//Do nothing
System.out.println("Startup");
}
}
我想使用FormActionImpl类,因为它可以访问JPA处理程序和数据库,我需要访问数据库。对于“forAction.migrateForms();”行,这不起作用(我得到一个nullpointerexception)。我最好的猜测是我不能使用注射,因为这些类已经在关闭的这个阶段被销毁了?
有没有办法在关机期间获得对托管bean的访问权限?或者以其他方式使用JPA?