3 Replies Latest reply on Jul 31, 2012 8:08 AM by Rafael Pestano

    Null InjectionPoint when injecting EJBs

    Rafael Pestano Novice

      Hi guys,

       

      i have a question about injecting EJBs, the following example works when using CDI beans:

       

       

       

      public interface MyInterface extends Serializable{
      
          String getValue();
      }
      
      

       

       

      @MyAnnotation
      public class CDIBean  implements MyInterface,Serializable {
      
          private String value;
      
      
          @Inject
          public void init(InjectionPoint ip){
              if(ip != null){ //its null when CDIBean is an EJB
                  value = ip.getAnnotated().getAnnotation(MyAnnotation.class).param();
              }
          }
      
      
        
          @Override
          public String getValue() {
              return value;
          }
      
      
      
          public void setValue(String value) {
              this.value = value;
          }
      
      }
      
      

       

      I use the following annotation to pass parammeter to the CDI bean via InjectionPoint

       

       

      @Qualifier
      @Retention(RUNTIME)
      @Target({TYPE, FIELD,PARAMETER,METHOD})
      public @interface MyAnnotation {
      
      
          @Nonbinding
          String param() default "";
      }
      
      

       

       

      @SessionScoped
      @Named
      public class MyController implements Serializable{
      
          @Inject @MyAnnotation(value="a value")
          private MyInterface myInterface;
      
      
          public MyInterface getMyInterface() {
              return myInterface;
          }
      
      
          public void setMyInterface(MyInterface myInterface) {
              this.myInterface = myInterface;
          }
      
      

       

      when my bean is annotated with @Stateless CDI still can inject it but the injectionPoint is null

       

       

      @MyAnnotation
      @Stateless // ip will be null
      public class CDIBean  implements MyInterface,Serializable {
      }
      
      

       

      So is this behavior expected?

       

      Im using Weld 1.1.4(shipped with Glassfish 3.1.2)

       

      Thanks in advance.