6 Replies Latest reply on Jan 29, 2010 3:22 AM by peteroyle.howardmoon.hitcity.com.au

    Bean instantiated twice

    pieter.martin

      Hi,


      I am using weld in the standalone SE manner.


      At the moment I only have 2 beans.



      @ApplicationScoped
      public class Entry {
      
           @Inject 
           TestInject testInject;
           
           public void train(@Observes ContainerInitialized event) {
                System.out.println("NeuralNetworkStart ");
                testInject.doStuff();
           }     
      }




      @ApplicationScoped
      public class TestInject {
      
           public TestInject() {
                super();
                System.out.println("TestInject constructor");
           }
           
           @PostConstruct
           public void postContruct() {
                System.out.println("postContruct");
           }
           
           @PreDestroy
           public void preDestroy() {
                System.out.println("preDestroy");
           }
      
           public void doStuff() {
                System.out.println("doin stuff u know");
           }
           
      }



      The TestInject class is instantiated twice. Once before the ContainerInitialized event fires and again before the doStuff method call.


      Further I noticed that the @PostConstruct fires but the @PreDestroy never fires.


      What am I doing wrong?


      Thanks
      Pieter