views:

69

answers:

1

Hi all,

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.

What am I missing?

Thanks,

Walter

+1  A: 

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/en-US/html/extend.html#d0e4984

Walter

Thanks for posting this. +1 all around.
Pascal Thivent