2 Replies Latest reply on Aug 9, 2011 5:29 AM by Vinicius Carvalho

    CDI how to startup bean?

    Vinicius Carvalho Newbie

      Hi there! I'm using weld 1.1.1.AS7 from jboss 7.


      I have a simple bean:




      @ApplicationScoped
      @Startup
      public class CamelLifeCycleFix {
      
           Logger logger = LoggerFactory.getLogger(CamelLifeCycleFix.class);
           
           @Inject CDICamelContext context;
           
           @PostConstruct
           public void afterCreate(){
                logger.debug("Look mom, I exist!");
           }
           
           public void shutdown(@Observes BeforeShutdown event){
                try {
                     context.stop();
                } catch (Exception e) {
                     // TODO: handle exception
                }
           }
      




      I was expecting this bean to be created on startup. but, the aftercreate does not get called on the bean deployment. Also it does not get called when a shutdown happens.


      The bad part is that if I force it on my Extension:


      beanManager.getReference(b, CamelLifeCycleFix.class, beanManager.createCreationalContext(b));


      It then works, I mean the post construct gets called.


      Does CDI support @Startup? Also, if this is an ApplicationScopped bean, shouldn't it be created on startup anyway?


      Have no idea why the shutdown never gets called.


      Someone have an idea out there, running out of options here :(