JNDI无EJB接收器可用于处理 [英] JNDI No EJB receiver available for handling

查看:151
本文介绍了JNDI无EJB接收器可用于处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的EJBTest有一个问题。



我已经安装了WildFly并配置了用户管理和应用程序管理。



我写了一个EJB 3.0并部署了它:

  @Stateless 
@Remote(NewSessionBeanRemote.class)
public class NewSessionBean实现NewSessionBeanRemote {

列表< String> bookShielf;

/ **
*默认构造函数。
* /
public NewSessionBean(){
bookShielf = new ArrayList< String>();
}

@Override
public void addBook(String bookName){
bookShielf.add(bookName);
}

@Override
public List getBook(){
return bookShielf;
}
}

之后,我写了一个简单的客户端来连接它:

  private static void invokeStatelessBean()throws NamingException {
//让我们查找远程无状态计算器
NewSessionBeanRemote remoteEjb = lookupRemoteSessionBean();
System.out.println(获取用于调用的远程无状态计算器);
String bookName =TEST book;
remoteEjb.addBook(bookName);
}

private static NewSessionBeanRemote lookupRemoteSessionBean()throws NamingException {

final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,org.jboss.ejb.client.naming);
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,org.jboss.naming.remote.client.InitialContextFactory);
jndiProperties.put(Context.PROVIDER_URL,http-remoting://127.0.0.1:10090);
jndiProperties.put(Context.SECURITY_PRINCIPAL,ejb); //这是应用程序用户名,不管理!这是正确的?
jndiProperties.put(Context.SECURITY_CREDENTIALS,ejb); //这是应用程序的密码,不管理!这是正确的?
jndiProperties.put(jboss.naming.client.ejb.context,true);
final Context context = new InitialContext(jndiProperties);
final String appName =;
final String moduleName =EjbComponent;
final String distinctName =;
final String beanName = NewSessionBean.class.getSimpleName();
final String viewClassName = NewSessionBeanRemote.class.getName();
System.out.println(ejb:+ appName +/+ moduleName +/+ distinctName +/+ beanName +!+ viewClassName);
return(NewSessionBeanRemote)context.lookup(ejb:+ appName +/+ moduleName +/+ distinctName +/+ beanName +!+ viewClassName);
}

用户名和密码都是应用程序用户凭据,不管理!是否正确?



我收到此错误:


线程mainjava.lang.IllegalStateException:EJBCLIENT000025:没有EJB接收器可用于处理[appName :, moduleName:EjbComponent,distinctName:]组合用于调用上下文org.jboss.ejb.client.EJBClientInvocationContext@5034c75a
在org .jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
在org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
在org.jboss.ejb .client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
在org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
在org.jboss.ejb.client.EJBInvocationHandler .doInvoke(EJBInvocationHandler.java:200)
在org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
在org.jbo ss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
在com.sun.proxy。$ Proxy2.addBook(未知来源)
在com.studio.java.client.EjbTester。 invokeStatelessBean(EjbTester.java:34)
在com.studio.java.client.EjbTester.main(EjbTester.java:21)


我不知道为什么!任何人都有想法?

解决方案

您收到上述错误,因为您尝试使用绝对访问远程EJB JNDI名称。



正如文档


http-remoting 客户端假定远程查找中的JNDI名称相对于java:jboss / exports命名空间,绝对JNDI名称的查找将失败。


因此,在将应用程序部署到WildFly之后,您应该在服务器控制台上看到类似的内容:

 部署单元部署中名为NewSessionBean的会话bean的JNDI绑定< your_deployment_unit>如下:

java:global [/< application_name>] /< module_name> /< ejb_name> [!< interface_name>]
java:app [/< $]
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>

因此,考虑到 java:jboss /导出的上下文,实现EJB的正确方法应该是:

  //通常appName是EAR名称
//离开它如果您的应用程序未打包在EAR中,则为空
String appName =your_application_name /;
// EJB模块名称
String moduleName =ejb_module_name /;
String beanName = NewSessionBean.class.getSimpleName();
String viewClassName = NewSessionBeanRemote.class.getName();

(NewSessionBeanRemote)context.lookup(appName + moduleName + beanName +!+ viewClassName);

为进一步阅读,我建议您还可以查看 Java EE JNDI语法以及 WildFly的JNDI参考



关于您的凭据,它们不是必需的,因为您的EJB不需要任何类型的身份验证,以便您访问它。通常情况下,您只需要使用例如使用 LDAP服务提供商


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:

@Stateless
@Remote(NewSessionBeanRemote.class)
public class NewSessionBean implements NewSessionBeanRemote {

    List<String> bookShielf;

    /**
     * Default constructor. 
     */
    public NewSessionBean() {
        bookShielf = new ArrayList<String>();
    }

    @Override
    public void addBook(String bookName) {
        bookShielf.add(bookName);
    }

    @Override
    public List getBook() {
        return bookShielf;
    }
}

Afterwards, I wrote a simple client to connect it:

private static void invokeStatelessBean() throws NamingException {
    // Let's lookup the remote stateless calculator
    NewSessionBeanRemote remoteEjb = lookupRemoteSessionBean();
    System.out.println("Obtained a remote stateless calculator for invocation");
    String bookName = "TEST book";
    remoteEjb.addBook(bookName);
}

private static NewSessionBeanRemote lookupRemoteSessionBean() throws NamingException {

    final Hashtable jndiProperties = new Hashtable();
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:10090");
    jndiProperties.put(Context.SECURITY_PRINCIPAL, "ejb"); //this is the application user name, not management! it's correct?
    jndiProperties.put(Context.SECURITY_CREDENTIALS, "ejb");//this is the application password, not management! it's correct?
    jndiProperties.put("jboss.naming.client.ejb.context", true);
    final Context context = new InitialContext(jndiProperties);
    final String appName = "";
    final String moduleName = "EjbComponent";
    final String distinctName = "";
    final String beanName = NewSessionBean.class.getSimpleName();
    final String viewClassName = NewSessionBeanRemote.class.getName();
    System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    return (NewSessionBeanRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
}

Both username and password are the application user credential, not management! Is it correct?

I'm receiving this error:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:EjbComponent, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@5034c75a at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798) at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128) at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186) at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200) at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183) at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146) at com.sun.proxy.$Proxy2.addBook(Unknown Source) at com.studio.java.client.EjbTester.invokeStatelessBean(EjbTester.java:34) at com.studio.java.client.EjbTester.main(EjbTester.java:21)

I don't know why! Anyone have an idea?

解决方案

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.

这篇关于JNDI无EJB接收器可用于处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆