0 Replies Latest reply on Mar 14, 2012 12:08 PM by Kirill Linnik

    @Stateless bean is not initialized when using Spring

    Kirill Linnik Newbie
      Hi there,
      One module of our application is made by third party company and it's Spring-based. That's should be OK, since Spring has enabled EJB injection and vice-versa. Injecting EJBs in Spring works fine, but if I follow manual (http://refcardz.dzone.com/refcardz/dependency-injection-in-ejb3) and do like this:
      @Local
      public interface MyDAO {
        
        public void test();
        
      }
      and:
      @Stateless
      public class MyDAOImpl extends AbstractStatelessSessionBean implements
          MyDAO {
      
        private static final long serialVersionUID = 4738436066552146052L;
      
        private MySpringService mySpringServiceService;
      
        @Override
        protected void onEjbCreate() throws CreateException {
          mySpringServiceService = (MySpringService) getBeanFactory()
              .getBean("mySpringService");
        }
      
        @Override
        public void test() {
          ...    
        }
      
      }
      Because in Spring:
      @Service("mySpringService")
      And after all done I inject this EJB in another EJB like:
      @EJB
      private MyDAO myDAO;
      On server startup I see:
      Caused by: java.lang.RuntimeException: 
      Could not resolve @EJB reference: 
      [EJB Reference: beanInterface 'MyDAO', beanName 'null', mappedName 'null', lookupName 'null', owning unit 'ComponentDeploymentContext@726473212
      {org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.AnotherDAOImpl}'] 
      for environment entry: env/AnotherDAOImpl/myDAO 
      in unit ComponentDeploymentContext@726473212{org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData.AnotherDAOImpl}
      It means, AFAIK, MyDAO is not an EJB and cannot be injected.
      Well, where I am wrong?