CDI-观察集装箱事件 [英] CDI - Observing Container Events

查看:84
本文介绍了CDI-观察集装箱事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试观察CDI Web应用程序的启动和关闭事件。我有一个侦听这些事件的ApplicationScoped bean:

I am trying to observe both the startup and shutdown events for a CDI web application. I have an ApplicationScoped bean that listens for those events:

@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);
    }

我在日志中看不到任何东西。

I don't see anything in the logs.

我还缺少什么?

推荐答案

感谢Pete Muir,解决方案是实施扩展接口。一旦完成该操作,再创建一个特殊文件,它就可以完美运行。

Thanks to Pete Muir, the solution was to implement the Extension interface. Once I did that, along with creating a special file, it worked perfectly.

要记住的是,如果您想观察(或处理)容器事件,您必须实现扩展接口,因为它是一个特殊事件。

The thing to remember is, if you want to observe (or act on) container events, you must implement the extension interface as it is a special event.

https://docs.jboss.org/weld/reference/latest/zh-CN/html/extend.html#d0e4984

沃尔特

这篇关于CDI-观察集装箱事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆