homaxto
homaxto

Reputation: 5709

Using Dependency Injection in POJO's to inject EJB's

Is it possible to inject ejb's into pojo's using the @EJB annotation? If it is, do I have to set up anything special on a JBoss server to make it work?

Please let us not discuss the rationale behind doing this - I am just trying to hack some old code to make it work :-)

Upvotes: 1

Views: 2208

Answers (2)

Ondra Žižka
Ondra Žižka

Reputation: 46796

Not sure, but EJB 3.1 should allow this.

Upvotes: 0

Aaron Digulla
Aaron Digulla

Reputation: 328546

Yes, if you can make JBoss create the Pojo for you.

Your problem is that you probably call new to create the Pojo and the framework can't intercept this which is why @EJB is ignored.

The solution is to use a factory to create your Pojos and tell the factory about the EJBs, so it can set them before returning the new Pojo.

Upvotes: 2

Related Questions