5 Replies Latest reply: Feb 15, 2012 5:40 AM by Andrew Hughes RSS

    Programmatic Lookup with AnnotationLiteral, @Produces and InjectionPoint, how?

    Andrew Hughes Newbie

      Hi Guys,


      I need to pass a runtime value into a qualified producer, but can't get this working. It seems like select() and InjectionPoint can't be used together, or can they?


      Code to explain (hopefully)...


      The @Qualifier & AnnotationLiteral





      public @interface ServiceId {

            @Nonbinding String value() default "";



      public class ServiceIdLiteral extends AnnotationLiteral<ServiceId > implements ServiceId {

          public String value;

           public ServiceIdLiteral(String value){

              this.value = value;



          String value() { return value; }



      The @Inject'n and Programmatic Lookup




      Instance<Service> serviceSource;




      Service service = serviceSource.select(new ServiceIdLiteral(theRuntimeServiceId)).get(); //FAILS IN THE @Produces


      The @Produces, which seems to never get the injection point when programmatic lookup above exec's....




      Service getServiceByServiceId(InjectionPoint ip) {

          ServiceId serviceId = ip.getAnnotated().getAnnotation(ServiceId.class).value(); //ALWAYS THROWS NPE!





      Since I can't see this documented and there are no examples, can someone confirm if what I am to achieve is even possible?



      Pete's comment (09-Mar-2010) on this post https://community.jboss.org/message/658227#658227 seems to indicate that this should work...





      p.s. yes... this question had a massive edit/rewrite.