此問題非常常見。我看過一些文章,但找不到問題。我想在EJB 3.0中創建一個簡單的HelloWorld程序,eclipse luna,jboss 7.1.1 Final。EJB 3的JNDI初始上下文和查找問題
這裏是我的豆:
package com.tcs.HelloWorldPack;
import javax.ejb.Stateless;
/**
* Session Bean implementation class HelloWorld
*/
@Stateless(mappedName="HelloWorldBean")
public class HelloWorld implements HelloWorldRemote {
/**
* Default constructor.
*/
public HelloWorld() {
// TODO Auto-generated constructor stub
}
@Override
public void displayMsg() {
// TODO Auto-generated method stub
System.out.println("Hello World!!");
}
}
這裏是我的遠程接口:
package com.tcs.HelloWorldPack;
import javax.ejb.Local;
//import javax.ejb.Remote;
import javax.ejb.Remote;
@Remote
public interface HelloWorldRemote {
void displayMsg();
}
這裏是我的客戶端,在同一臺機器上運行:
package com.tcs.HelloWorldClient;
import java.util.Hashtable;
import java.util.Properties;
import com.tcs.HelloWorldPack.*;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class HelloWorldClient {
public static void main(String[] args) throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(javax.naming.Context.SECURITY_PRINCIPAL, "myUser");
jndiProperties.put(javax.naming.Context.SECURITY_CREDENTIALS, "myPass");
// jndiProperties.put(javax.naming.Context.PROVIDER_URL, "jnp://localhost:1099");
// jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put("jboss.naming.client.ejb.context", true);
final Context context = new InitialContext(jndiProperties);
final String appName= "HeloWorldEJBEAR";
final String moduleName= "";
final String distinctName ="";
final String beanName = "HeloWorld";
final String viewClassName = "com.tcs.HelloWorldPack.HelloWorldRemote";
HelloWorldRemote hello = (HelloWorldRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
hello.displayMsg();
}
}
這是我的jboss-ejb-client.properties文件:
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
remote.connection.default.username=myUser
remote.connection.default.password=myPass
我已經把屬性文件在classpath also.But當我試圖運行它發生這種情況:
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:HeloWorldEJBEAR,modulename:,distinctname:] combination for invocation context [email protected]
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 com.sun.proxy.$Proxy0.displayMsg(Unknown Source)
at com.tcs.HelloWorldClient.HelloWorldClient.main(HelloWorldClient.java:71)
Jan 08, 2015 3:34:44 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleEnd
INFO: Channel Channel ID de8d2aa6 (outbound) of Remoting connection 44477156 to localhost/127.0.0.1:4447 can no longer process messages
我還上傳了我的目錄結構。我對EJB概念很陌生。請幫我找出問題所在。提前致謝。
您是否已將ejb模塊添加到ejb客戶端中。 –
對不起,我不明白你在問什麼。我有一個ejbmodule與我的會話bean和另一個ejbmodule相關聯,用於我的客戶端@Manoj Sharma – Ajit