1 Reply Latest reply on Jul 20, 2011 11:41 AM by Vinicius Carvalho

    How to Scan for annotations

    Vinicius Carvalho Newbie

      Hi there! I'm implementing a CDI extension, and one thing I need to do is scan for a given annotation, and then get the method its used and register it within one of my services. let's say:



      @Consumes
      public void method(Type x){}




      I know I could easily do that by using interceptors, and aroundinvoke, but It will require enabling it on beans.xml for every module (something I'm trying to avoid).


      On Spring we did this by using a beanpostprocessor and postProcessBeforeInitialization(Object bean, String beanName) we scan the bean for methods with the annotation. How could I achieve the same with Weld and CDI? I had a brief look at Solder but could not find how to do it with it either.


      Cheers

        • 1. Re: How to Scan for annotations
          Vinicius Carvalho Newbie

          Well, if anyone is interested I solved this by:




          <T> void processInjectionTarget(@Observes final ProcessInjectionTarget<T> pit, final BeanManager beanManager){
          if(containsAnnotation(pit.getAnnotatedType()){
          annotationSet.put(pit.getAnnotatedType());
          }
          }





          ... Later on




          void afterDeploymentValidation(@Observes AfterDeploymentValidation add, final BeanManager beanManager){
          for(AnnotatedType a : annotationSet){
          //do what I need to do :)
          }
          }
          




          Cheers