JNDI No EJB receiver available for handling

后端 未结 1 987
遥遥无期
遥遥无期 2021-01-24 02:22

I have a problem with my EJBTest.

I have installed WildFly and configured user management and application management.

I wrote an EJB 3.0 and deployed it:

相关标签:
1条回答
  • You're receiving the mentioned error because you're trying to access a remote EJB using the absolute JNDI name.

    As stated by the documentation:

    The http-remoting client assumes JNDI names in remote lookups are relative to java:jboss/exported namespace, a lookup of an absolute JNDI name will fail.

    So, after you've deployed your application on WildFly, you should see something like this on your server console:

    JNDI bindings for session bean named NewSessionBean in deployment unit deployment <your_deployment_unit> are as follows:
    
        java:global[/<application_name>]/<module_name>/<ejb_name>[!<interface_name>]
        java:app[/<module_name>]/<ejb_name>[!<interface_name>]
        java:module/<ejb_name>[!<interface_name>]
        java:jboss/exported[/<application_name>]/<module_name>/<ejb_name>[!<interface_name>]
        java:global/[/<application_name>]/<module_name>/<ejb_name>
        java:app[/<module_name>]/<ejb_name>
        java:module/<ejb_name>
    

    Therefore, taking into account the java:jboss/exported context, the correct way of attaining your EJB should be:

    // Normally the appName is the EAR name
    // Leave it empty if your application isn't packaged in a EAR
    String appName = "your_application_name/";
    // The EJB module name
    String moduleName = "ejb_module_name/";
    String beanName = NewSessionBean.class.getSimpleName();
    String viewClassName = NewSessionBeanRemote.class.getName();
    
    (NewSessionBeanRemote) context.lookup(appName + moduleName + beanName + "!" + viewClassName);
    

    For further reading, I'd suggest you also to take a look at the Java EE JNDI Syntax as well as to WildFly's JNDI Reference.

    Regarding your credentials, they're not necessary since your EJB does not require any type of authentication in order for you to access it. Normally, that's only necessary when you have, for example, an application that uses a LDAP service provider.

    0 讨论(0)
提交回复
热议问题