tags:

views:

140

answers:

1

Hello,

does anyone knows how to "plug in" or enable IOC for injecting @EJB in classes which are not EJBs or Servlets (but rather POJOs)? So, if EJB and Servlet use helper classes, their EJB annotations are not processed. Application server is Glassfish v2.1.

Is there a way to enable this with some lightweight framework?

  1. Guice doesn't work with EJBs smoothly.

  2. Spring is too bloated for my needs (existing large application).

Basically I'm trying to remove JNDI lookups from many helper classes.

Do you have any suggestions?

Thank you,

Bozo

A: 

Try adding a Local interfaces for those helper classes, and annotate them (the classes) with @Stateless. Thus they can be recognized as parts of the EJB context. Then inject them in your EJBs using the Local interfaces.

Bozho
So you basically suggest that I convert POJOs to EJBs. While it can be done in some cases, it cannot be done in all the cases.
bozo
It should be possible for the cases where you need the helpers to be part of EJB context - for instance when they need a PersistenceContext injected. In cases the helper classes don't need to be in the EJB context, just instantiate them: private Helper helper = new Helper();
Bozho