Java 没有可用于处理 [appName:,modulename:HelloWorldSessionBean,distinctname:] 的 EJB 接收器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19902031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:]
提问by zoit
I'm trying to develop my first EJB with an Example I found, I have the next mistake:
我正在尝试使用我发现的示例开发我的第一个 EJB,我有下一个错误:
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorldSessionBean,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@41408b80
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at $Proxy0.sayHello(Unknown Source)
at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:16)
I use JBOSS 7.1, and the code is this: HelloWorld.java package com.ibytecode.business;
我用的是JBOSS 7.1,代码是这样的:HelloWorld.java package com.ibytecode.business;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String sayHello();
}
HelloWorldBean.java package com.ibytecode.businesslogic;
HelloWorldBean.java 包 com.ibytecode.businesslogic;
import com.ibytecode.business.HelloWorld;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloWorldBean
*/
@Stateless
public class HelloWorldBean implements HelloWorld {
/**
* Default constructor.
*/
public HelloWorldBean() {
}
public String sayHello() {
return "Hello World !!!";
}
}
}
EJBApplicationClient.java:
EJBApplicationClient.java:
package com.ibytecode.client;
import javax.naming.Context;
import javax.naming.NamingException;
import com.ibytecode.business.HelloWorld;
import com.ibytecode.businesslogic.HelloWorldBean;
import com.ibytecode.clientutility.ClientUtility;
public class EJBApplicationClient {
public static void main(String[] args) {
// TODO Auto-generated method stub
HelloWorld bean = doLookup();
System.out.println(bean.sayHello()); // 4. Call business logic
}
private static HelloWorld doLookup() {
Context context = null;
HelloWorld bean = null;
try {
// 1. Obtaining Context
context = ClientUtility.getInitialContext();
// 2. Generate JNDI Lookup name
String lookupName = getLookupName();
// 3. Lookup and cast
bean = (HelloWorld) context.lookup(lookupName);
} catch (NamingException e) {
e.printStackTrace();
}
return bean;
}
private static String getLookupName() {
/*
The app name is the EAR name of the deployed EJB without .ear suffix.
Since we haven't deployed the application as a .ear,
the app name for us will be an empty string
*/
String appName = "";
/* The module name is the JAR name of the deployed EJB
without the .jar suffix.
*/
String moduleName = "HelloWorldSessionBean";
/*AS7 allows each deployment to have an (optional) distinct name.
This can be an empty string if distinct name is not specified.
*/
String distinctName = "";
// The EJB bean implementation class name
String beanName = HelloWorldBean.class.getSimpleName();
// Fully qualified remote interface name
final String interfaceName = HelloWorld.class.getName();
// Create a look up string name
String name = "ejb:" + appName + "/" + moduleName + "/" +
distinctName + "/" + beanName + "!" + interfaceName;
return name;
}
}
ClientUtility.java package com.ibytecode.clientutility;
ClientUtility.java 包 com.ibytecode.clientutility;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ClientUtility {
private static Context initialContext;
private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
Properties properties = new Properties();
properties.put("jboss.naming.client.ejb.context", true);
properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
initialContext = new InitialContext(properties);
}
return initialContext;
}
}
}
properties.file:
属性文件:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
This is what I have. Why I have this?. Thanks so much. Regards
这就是我所拥有的。为什么我有这个?。非常感谢。问候
采纳答案by LMG
Let's try with the following, I can't type it in a comment because it goes pretty long.
让我们尝试以下内容,我无法在评论中输入它,因为它很长。
Seems that everything is fine, you can also leave the @Remote
without any problem. I will also assume that you get the right path to your EJB: how to check it?
似乎一切都很好,您也可以@Remote
毫无问题地离开。我还将假设您获得了通往 EJB 的正确路径:如何检查它?
When you deploy it you should see in the server console something like this:
部署它时,您应该在服务器控制台中看到如下内容:
ejb:{app-Name}/{module-Name}/{distinct-Name}/{bean-Name}!{fullPath-remote-Interface}
ejb:{app-Name}/{module-Name}/{distinct-Name}/{bean-Name}!{fullPath-remote-Interface}
EG: the first one is the one you are interested in (from lookup)
EG:第一个是您感兴趣的(来自查找)
java:global/MyBankLogicEAR/MyBankLogic/Account!main.IAccount
java:app/MyBankLogic/Account!main.IAccount
java:module/Account!main.IAccount
java:jboss/exported/MyBankLogicEAR/MyBankLogic/Account!main.IAccount
java:global/MyBankLogicEAR/MyBankLogic/Account
java:app/MyBankLogic/Account
java:module/Account
I will try to change the look up in the following way
我将尝试通过以下方式更改查找
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try {
final Context context = new InitialContext(jndiProperties);
String appName = "";
String moduleName = "jboss-firstbean";
String distinctName = "";
String beanName = "FirstBean";
String interfaceFullName = "ejb.RemoteFirstBean";
final String jndi = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName;
RemoteFirstBean statelessRemote = (RemoteFirstBean)context.lookup(jndi);
} catch (NamingException ex) {
System.out.println("problems");
}
this is taken from Accessing remote EJB on JBoss AS 7.1 from web application , I also suggest you to check step 5 in very same page in order to understand if you need to configure other properties in your jboss-ejb-client.properties file..
这是从 Web 应用程序访问 JBoss AS 7.1 上的远程 EJB 中获取的,我还建议您检查同一页面中的第 5 步,以了解您是否需要在 jboss-ejb-client.properties 文件中配置其他属性。