JBoss Community

@Stateless bean is not initialized when using Spring

created by Kirill Linnik in EJB3 - View the full discussion
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() {
    ...    
  }

}
where:
@Service("mySpringService")
and 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?

Reply to this message by going to Community

Start a new discussion in EJB3 at Community