문제

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 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

다른 팁

The "special file" mentioned by Walter White is:

META-INF/services/javax.enterprise.inject.spi.Extension

That file should contain the fully-qualified name of your Extension class. ie:

org.mydomain.extension.MyExtension
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top