Hello,
dependency injection only works in container managed objects. That's Session
Beans, Message Driven Beans or Entities, Servlets and JSF Managed Beans. It
does NOT work in POJO's. If you want to lookup an EJB from your PJO you have
to look it up manually.
Example:
try {
Context c = new InitialContext();
c.lookup("java:comp/env/ejb/myejb"); // <- put your JNDI name
here, where it says "myejb"
} catch(javax.naming.NamingException ne) {
// TODO
}
}
Hope, that helps.
Regards,
Joerg
----- Original Message -----
From: <glassfish_at_javadesktop.org>
To: <users_at_glassfish.dev.java.net>
Sent: Friday, May 09, 2008 1:21 PM
Subject: How to address / lookup a local interface from a helper class
> We have a stateless SessionBean "OrderManagementBean" which implements
> both local and remote interfaces.
> We try to call it from a helper class of another MDB and therefore
> injection via @EJB does not work.
>
> Currently we do lookup and get the remote. But for the helper class
> CreateOrder we would like to get the local interface.
>
> Our question is how to address the local interface?
>
>
> ---
> public class CreateOrder
> implements ApplicationRule {
>
> private OrderManagerInterface manager = null;
> // ...
> public ApplicationMessage action( ApplicationMessage inMessage )
> throws ApplicationRuleException {
>
> try {
> if ( null == manager ) {
> InitialContext context = new InitialContext();
> manager = (OrderManagerInterface)context.lookup(
> OrderManagerRemote.DEFAULT_JNDI_NAME );
> }
>
> // ...
> }
> ---
> @Local
> public interface OrderManagerLocal
> extends OrderManagerInterface {
> // ...
> }
> ---
> @Remote
> public interface OrderManagerRemote
> extends OrderManagerInterface {
>
> public final static String DEFAULT_JNDI_NAME = "ejb/OrderManagerBean";
> // ...
> }
> ---
> @Stateless( mappedName=OrderManagerRemote.DEFAULT_JNDI_NAME )
> public class OrderManagerBean
> implements OrderManagerRemote, OrderManagerLocal {
> // ...
> }
> [Message sent by forum member 'ralf_zalas' (ralf_zalas)]
>
> http://forums.java.net/jive/thread.jspa?messageID=273496
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>