reference EJB from servlet's action/helper classes

Hello

How to make a reference to stateless session bean from one of the helper classes of a servlet WITHOUT using any of these:

* dependency injection (like @EJB) - I think this is not supported in this kind of class, EJB references can be injected only to servlets themselves or some other things (but not objects of classes "accompanying" a servlet)

* home or local home interfaces (I would like to avoid writing them)

* using mappedName (either in @Stateless or in ejb-jar) - since meaning of this is application-server dependent and thus not portable.

By a "class accompanying a servlet" / "helper class" I mean utility or action classes, like MyActionClass, which would be instantiated and then used by a aforementioned servlet.

Thanks.

[784 byte] By [STFa] at [2007-11-27 9:08:52]
# 1

The EJB dependency must be looked up via the java:comp/env namespace since as you point out

Java EE 5 environment annotations are not supported on POJOs.However, the dependency itself

can either be defined using @EJB on some *other* managed class in the .war or within the

web.xml.We have an entry in our EJB FAQ that has the details :

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB

Also, whenever the client component resides in the same application as the target EJB (which is

required for Local access but not for Remote access) there is no need to use mappedName to

resolve the EJB dependency.It is either automatically resolved if the business interface type of

the EJB dependency is only exposed by a single EJB in the application, OR the beanName()

/ ejb-link attributes can be used to unambiguously identify the target EJB using ejb-name.

You can find more about this in the FAQ as well.

ksaksa at 2007-7-12 21:47:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...