EJB lookup fails during startup but is fine when the call is made after the server is started.

Latest response

HI All

I am using Jboss EAP 7.1. And i managed to deploy a stateless EJBbean successfully.

And i am also able to access the deploy EJB after the server is started successfully. using the below piece of code.

final Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put("jboss.naming.client.ejb.context", true);
    Context context;
    try {
        context = new InitialContext(jndiProperties);
        String appName = "";

        if ("FlowControllerBean/remote".equalsIgnoreCase(jndiName)) {
            appName = "";

        } else {
            appName = "upm-0.1";
        final String distinctName = "";
        String beanName = "";
        final String viewClassName = FlowController.class.getName();
                "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
        if ("".equalsIgnoreCase(interfacename)) {
            context = new InitialContext();
            return context.lookup(jndiName);
        } else {
            beanName = jndiName.substring(0, jndiName.indexOf("/"));
            return context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!"
                    + interfacename);
    } catch (NamingException e) {
        // TODO Auto-generated catch block
    return null;

But my real problem comes when i want to access the same EJB during server start up itself. One of my method inside a service bean calls this EJB Bean during server startup itself. But it fails with the message "EJBCLIENT000079: Unable to discover destination for request for EJB StatelessEJBLocator for "/ejb-remote-server/FlowControllerBean", view is interface com.hexaware.framework.flowcontroller.FlowController, affinity is None".

Before the lookup is executed the actual EJB beans are deployed. Please find below the logs from server before the lookup is made during start up.

14:36:25,971 INFO [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment ejb-remote-server.jar

14:36:26,373 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'FlowControllerBean' in deployment unit 'deployment "ejb-remote-server.jar"' are as follows:


[org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-4) Setting the server's publish address to be http://localhost:8080/ejb-remote-server/EventManagerService
14:36:29,409 INFO [org.jboss.ws.cxf.deployment] (MSC service thread 1-4) JBWS024074: WSDL published to: file:/D:/Magesh/Softwares/Jboss-eap-7.1/standalone/data/wsdl/ejb-remote-server.jar/EventManagerServiceService.wsdl
14:36:29,643 INFO [org.jboss.as.webservices] (MSC service thread 1-4) WFLYWS0003: Starting service jboss.ws.endpoint."ejb-remote-server.jar".EventStatusService
14:36:29,650 INFO [org.jboss.as.webservices] (MSC service thread 1-2) WFLYWS0003: Starting service jboss.ws.endpoint."ejb-remote-server.jar".EventManagerService
14:36:30,197 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 72) WFLYUT0021: Registered web context: '/ejb-remote-server' for server 'default-server'

But the same code works if i call it after the server is started completely.

Please help.
Below is how i have defined my EJBbean.

@Stateless(mappedName = "FlowController/remote")
public class FlowControllerBean implements FlowController
public TransferObject execute(TransferObject transferObject) throws ApplicationException {

Below is my property file which i have used for connecting from the client to my remote server.Both server and client are in same Jboss server instance in my local machine.

remote.connection.default.port = 8080

Note: Look up is successful during startup or any other time. But when i try to call a method in the bean the error message is encountered. But same bean method call works after server startup

M Magesh Kumar


You cannot remotely invoke an EJB on a server that is not up and running. The ejb: lookup does not actually make a remote call, so it will return a proxy without connecting to the remote machine.