Recommended way of invoking a EJB local interface method is to perform a lookup:
<code>
Context ic = new IntialContext();
ic.lookup(objectJndiName);
</code>
However, I browse the complete JNDI tree at the start of application and at the end I am able to create a map of all objects with:
<code>
Map <String,Object>
</code>
with key ObjectName and object of required Interface Implementation. I search the object with key and invoke the required method on interface like this:
method.invoke(bean, args);
Is this method ok? or should I perform lookup for the required ejb everytime?
JNDI lookups is not the recommended way for instantiating references of Local Interfaces of Stateless beans, as from EE5 and above. Simply injecting the bean with @EJB annotation or CDI's @Inject will do the job fine.