0 Replies Latest reply on Dec 7, 2010 2:18 PM by cernicb

    Injecting parameterized beans

    cernicb

      Hi,


      I'm learning cdi and don't quite understand how to inject parameterized beans. I use glassfish 3.0.1 final. I have one generic slsb:


      @Stateless
      @Dependent
      public class GenericBean<T extends BaseObject, I extends Serializable> implements Serializable {
      ...
      }
      


      where BaseObject is base class of all entities and is also generic:


      public abstract class BaseObject<I extends Serializable> implements Serializable {
      ...
      }
      


      so I use it raw for now. Next I have jsf managed bean:


      @SessionScoped
      @Named
      public class Login implements Serializable {
           
           GenericBean<User, Long> genericBean;
           
           public Login() {
           }
           
           @Inject
           public Login(GenericBean<User, Long> genericBean) {
                this.genericBean = genericBean;
                System.out.println(this.genericBean.find(User.class, 1006L));
           }
      }
      


      where User is my only entity that extends BaseObject<Long>.


      In this arrangement everything works fine. However, if I change GenericBean class so that BaseObject param is not raw any more:


      @Stateless
      @Dependent
      public class GenericBean<T extends BaseObject<I>, I extends Serializable> implements Serializable {
      ...
      }
      


      I get a


      Exception while loading the app : org.glassfish.deployment.common.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies. Injection point: parameter 1 of constructor public org.login.jsf.Login(org.login.model.Credentials,org.login.session.GenericBean); Qualifiers: [@javax.enterprise.inject.Default()]
      


      when try to deploy application. Is that okay? If it's okay, why is it?


      Also, that second id parameter, I, extends Serializable and I get warning within eclipse that says No bean is eligible for injection to the injection point on genericBean injection point, but in runtime, everything is fine. If I extend Comparable instead of Serializable, warning disapears. I use Helios Service Release 1.