Reputation: 702
I am using EJB3.1 deployed to JBoss AS 5.1, so I'm using the @EJB injection. It works great when called from another EJB. Like this bean:
@Stateless (mappedName = "daos/MyDao")
public class MyDAO implements MyDaoRemote {
@PersistenceContext(unitName = "myEm")
private EntityManager em;
which is injected into this other bean
@Stateless(mappedName = "handler/MyHandler")
public class MyHandler implements MyHandlerRemote {
@EJB(mappedName = "daos/MyDao")
private MyDaoRemote myDao;
However, my application starts from a POJO. I don't think you can use the @EJB injection outside of a EJB... SO, is it possible to get MyHandler without using a JNDI lookup? This code works:
return (MyHandlerRemote) new InitialContext().lookup("handler/MyHandler");
but I would love to avoid doing this lookup. In Seam and Spring, it seems like the scanning of classes for annotations is easier.
I probably don't NEED @EJB injection, but I like having the container manage the PersistenceContext for me, and the auto-wiring.
Seems like Weld could help, but I don't think it will work in JBoss AS 5.1, as could Spring, but it seems like there should be a starting point for EJB without JNDI lookups.
Thanks in advance.
Upvotes: 2
Views: 1397
Reputation: 236170
You can use Seam for injecting EJBs in POJOs running under JBoss AS 5.1, without the need for making a JNDI lookup - instead, using Seam's @In
annotation.
Upvotes: 3