我正在尝试观察 CDI Web 应用程序的启动和关闭事件。我有一个监听这些事件的 ApplicationScoped bean:
@ApplicationScoped
public class PrettyfacesStartupObserver
{
private static final Log LOGGER = LogFactory.getLog(PrettyfacesStartupObserver.class);
public PrettyfacesStartupObserver()
{
LOGGER.debug("\n\n\n\n\n\n\n\n\n\nconstructor");
}
public void onStartup(@Observes
AfterBeanDiscovery afterBeanDiscovery
)
{
LOGGER.debug("\n\n\n\n\n\n\n\n\n\nafter bean discover");
}
public void onStartup(@Observes
AfterDeploymentValidation afterDeploymentValidation
)
{
LOGGER.debug("\n\n\n\n\n\n\n\n\n\n\nafter deployment validation");
}
public void onShutdown(@Observes
BeforeShutdown beforeShutdown
)
{
LOGGER.debug("\n\n\n\n\n\n\n\n\n\n\nbefore shutdown:" + beforeShutdown);
}
我在日志中看不到任何内容。
我错过了什么?
最佳答案
感谢 Pete Muir,解决方案是实现 Extension 接口(interface)。一旦我这样做了,并创建了一个特殊文件,它就完美地工作了。
要记住的是,如果你想观察(或作用于)容器事件,你必须实现扩展接口(interface),因为它是一个特殊事件。
https://docs.jboss.org/weld/reference/latest/en-US/html/extend.html#d0e4984
沃尔特
关于java-ee-6 - CDI - 观察容器事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3540137/