0 Replies Latest reply on Jul 26, 2011 7:11 AM by Vinicius Carvalho

    Bean not found on JBossAS 6

    Vinicius Carvalho Newbie

      Hi there! I'm developing a CDI extension. And I've just hit a dead end.


      my EAR has an EJB module with the extension and a WAR module with some beans.


      My problem is that on JBossAS7 the following code works on my extension:




      private void createConsumers(CamelContext ctx, BeanManager beanManager){
                logger.debug("Creating consumer beans");
                
                CamelPostProcessorHelper helper = new CustomCamelPostProcessorHelper(ctx);
                for(Class<?> c : consumerBeans){
                     logger.debug("Creating consumer for class: " + c.getName());
                     Set<Bean<?>> beans = beanManager.getBeans(c);
                     logger.debug("Found " + beans.size() + " beans registred for type [" +c.getName()+"]");
                     for(Bean b : beans){
                          final CreationalContext<?> creationalContext = beanManager.createCreationalContext(b);     
                          Object beanRef = beanManager.getReference(b, b.getBeanClass(), creationalContext);
                          String beanName = b.getName();
                          if(beanName == null){
                               beanName = b.getBeanClass().getName(); 
                          }
                          
                          logger.debug("Scanning methods with @Consumes annotation for bean: " + beanName);
                          Set<Method> annotatedSet = getAnnotatedMethods(c);
                          logger.debug("Found " + annotatedSet.size() + " methods annotated with @Consumes for bean " + beanName);
                          for(Method m : annotatedSet){
                               Consumes con = getConsumesAnnotation(m.getAnnotations());
                               if(con != null){
                                    String uri = con.uri();
                                    logger.debug("Found @Consumes(uri="+uri+") at method " + m.getName());
                                    logger.debug("Subscribing this method to camel context");
                                    try {
                                         helper.subscribeMethod(m, beanRef, beanName, uri, "");
                                    } catch (Exception e) {
                                         logger.error("Could not subscribe method " + m.getName()+"@"+c.getName() + " from " + beanName +"@" + beanRef.getClass().getName() + " with uri: " + uri,e);
                                    }
                               }
                          }
                     }
                }
           }



      But on JBoss AS 6, the line: beanManager.getBeans(c) returns an empty set. For some reason, the beans on the webmodule are not found :(


      On JBossAS7 it works fine. But, on AS7 the JIRA #WELD-891 makes deployment on AS7 not possible, since I can not shutdown the camel context using BeforeShutdown observers:




      void beforeShutdown(@Observes BeforeShutdown shutdown, final BeanManager beanManager) {
                Set<Bean<?>> beans = beanManager.getBeans(CDICamelContext.class);
                CamelContext context = null;
                for(Bean b : beans){
                     context = (CamelContext) beanManager.getReference(b, CamelContext.class, beanManager.createCreationalContext(b));
                }
                if(context != null){
                     try {
                          logger.debug("shutting down camel context");
                          context.stop();
                     } catch (Exception e) {
                          logger.error(e.getMessage(), e);
                     }
                }
           }



      So I guess until issue 891 gets fixed, I'll have to stuck with AS6. Any ideas on why it can not find the beans from the war module?


      Regards