I have an @ApplicationScoped bean. It observes ContainerInitialized and 
ContainerShutdown event.    public Kernel()
    {
        System.out.println("Kernel constructed");
    }

    public void onContainerInitialized(@Observes ContainerInitialized event, 
@Parameters List<String> parameters) {
        System.out.println("container initialized");
    }

    public void onContainerShutdown(@Observes ContainerShutdown event){
        System.out.println("container shutdown");
    }Then the kernel is constructed twice with the code below, one after boot, 
one after shutdown.

public class Test {
    public static void main(String[] args) {
        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
        cdiContainer.boot();

        // Starting the application-context enables use of @ApplicationScoped 
beans
        ContextControl contextControl = cdiContainer.getContextControl();
        contextControl.startContext(ApplicationScoped.class);

        // You can use CDI here
        contextControl.stopContext(ApplicationScoped.class);
        cdiContainer.shutdown();
    }
}
If I remove the ContextControl related code. Then it is constructed only once 
after boot.


If I keep the ContextControl related code and remove the observation of 
ContainerInitialized. Then it is constructed only after shutdown.
If I keep the ContextControl related code and remove the observation of 
ContainerShutdown. Then it is constructed only after shutdown.


What I expect is it is constructed only once after boot even I keep the 
ContextControl related code.

Reply via email to