9 Replies Latest reply on Feb 15, 2017 7:21 AM by gprade

    @Inject CDI Wildfly 10 with interfaces doesn`t seem to work like it used to in previous versions of JBoss AS7

    amostech

      Good evening,

      I finally decided to move to Wildfly 10 in order to get hands on the new features of Java EE 7 and all the cool stuff that has been developed in this project. But it turns out that I bumped into a problem that is kind of making me feel confused about the ways things work here.

       

      The problem:

           Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type FriendRequestDaoImpl with qualifiers @Default

       

      The cause:

           Whenever I try to inject a bean that implements an interface this error occurs.

       

      Example that works:

       

      @Stateless
      public class FriendRequestDaoImpl extends GenericDaoImpl<FriendRequest> {
      
          @Inject
          private EntityManager em;
          
          public FriendRequestDaoImpl() {
          }
          
        public List<FriendRequest> findFriendRequestByReceiver(Long receiverId) {
           // IMPLEMENTATION OF METHOD...     
        }
          
      }
      

      Example that won't work and generate the exception I mentioned above:

       

       

      @Stateless
      public class FriendRequestDaoImpl extends GenericDaoImpl<FriendRequest> implements FriendRequestDao {
      
          @Inject
          private EntityManager em;
          
          public FriendRequestDaoImpl() {
        }
          
        public List<FriendRequest> findFriendRequestByReceiver(Long receiverId) {
           // IMPLEMENTATION OF METHOD...     
        }
          
      }
      

       

       

      You see? The only difference between the example that works and the one that doesn`t is that the latter implements the FriendRequestDao interface which has the following structure:

       

      @Local
      public interface FriendRequestDao extends GenericDao<FriendRequest> {
      
       /** Specializations...*/
         public List<FriendRequest> findFriendRequestByReceiver(Long receiverId);
      }
      

       

      The GenericDao interface is as follows:

       

      
      public interface GenericDao<T> {
      
        T register(T t);
      
        void delete(Object id);
      
        T find(Object id);
      
        T update(T t);
      
      }
      
      

       

      It seems to me that when the Inheritance structure gets a little complicated WELD cannot understand how to instantiate the beans anymore, would that make sense?

       

      Do I correctly understand the way CDI and injection is supposed to work in Wildfly 10? I am pretty sure this structure used to work back when we used JBoss AS 7 and Java EE6.

       

      Thank you very much! =)

      Arthur