2

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
javatestcase
  • 682
  • 1
  • 10
  • 25

1 Answers1

3

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • I'm familiar with Seam, and I agree it would work. I suppose since Seam used a version of Weld before it went JSR, it's pretty similar. Since I don't think the problem can truly be solved, this is as good as we can do. – javatestcase Dec 29 '11 at 01:09