我Jboss装的是7.1的......Eclipse集成安装都没问题...EJB的项目就打印了个东西
package cn.itcast.ejb3.impl;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import cn.itcast.ejb3.HelloWorld;
@Stateless
@Remote(HelloWorld.class)
public class HelloWorldBean implements HelloWorld {
@Override
public String sayHello(String name) {
return name+"你好,世界";
}
}
项目发布也成功了...
现在写了个客户端的代码如下
package cn.itcast.test;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import cn.itcast.ejb3.HelloWorld;
import cn.itcast.ejb3.impl.HelloWorldBean;
public class EJBClient {
/**
* @param args
*/
public static void main(String[] args) {
Hashtable<String,String> jndiProperties = new Hashtable<String,String>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try{
Context context = new InitialContext(jndiProperties);
final String appName = "";
final String moduleName = "HelloWorld";
final String distinctName = "";
final String beanName = HelloWorldBean.class.getSimpleName();
final String interfaceName = HelloWorld.class.getName();
HelloWorld hwr = (HelloWorld)context.lookup("ejb:"+ appName + "/" + moduleName + "/" + distinctName +
"/HelloWorldBean!cn.itcast.ejb3.HelloWorld");
System.out.println("ejb:"+ appName + "/" + moduleName + "/" + distinctName +
"/" + beanName+"!"+interfaceName);
// HelloWorld hwr = (HelloWorld)context.lookup("HelloWorldBean/remote");
System.out.println("ok");
String say = hwr.sayHello("帅哥");
System.out.println(say);
}catch(Exception e){
e.printStackTrace();
}
//-----------------------------------------------------------
// Properties props = new Properties();
//
// props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
//
// props.setProperty(Context.PROVIDER_URL, "localhost:1099");
// try{
//
// InitialContext cts = new InitialContext(props);
// System.out.println("ok");
// HelloWorld helloworld = (HelloWorld) cts.lookup("HelloWorldBean/remote");
// System.out.println(helloworld.sayHello("帅哥"));
// }catch(Exception e){
// e.printStackTrace();
// }
}
}
屎都运行不出来........
报错代码如下
2013-2-17 15:56:23 org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 1.0.5.Final
ejb:/HelloWorld//HelloWorldBean!cn.itcast.ejb3.HelloWorld
ok
2013-2-17 15:56:23 org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration createConnectionConfiguration
INFO: No port configured for connection named default. Skipping connection creation
java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@defa1a
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 cn.itcast.test.EJBClient.main(EJBClient.java:34)
求解......
package cn.itcast.ejb3.impl;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import cn.itcast.ejb3.HelloWorld;
@Stateless
@Remote(HelloWorld.class)
public class HelloWorldBean implements HelloWorld {
@Override
public String sayHello(String name) {
return name+"你好,世界";
}
}
项目发布也成功了...
现在写了个客户端的代码如下
package cn.itcast.test;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import cn.itcast.ejb3.HelloWorld;
import cn.itcast.ejb3.impl.HelloWorldBean;
public class EJBClient {
/**
* @param args
*/
public static void main(String[] args) {
Hashtable<String,String> jndiProperties = new Hashtable<String,String>();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try{
Context context = new InitialContext(jndiProperties);
final String appName = "";
final String moduleName = "HelloWorld";
final String distinctName = "";
final String beanName = HelloWorldBean.class.getSimpleName();
final String interfaceName = HelloWorld.class.getName();
HelloWorld hwr = (HelloWorld)context.lookup("ejb:"+ appName + "/" + moduleName + "/" + distinctName +
"/HelloWorldBean!cn.itcast.ejb3.HelloWorld");
System.out.println("ejb:"+ appName + "/" + moduleName + "/" + distinctName +
"/" + beanName+"!"+interfaceName);
// HelloWorld hwr = (HelloWorld)context.lookup("HelloWorldBean/remote");
System.out.println("ok");
String say = hwr.sayHello("帅哥");
System.out.println(say);
}catch(Exception e){
e.printStackTrace();
}
//-----------------------------------------------------------
// Properties props = new Properties();
//
// props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
//
// props.setProperty(Context.PROVIDER_URL, "localhost:1099");
// try{
//
// InitialContext cts = new InitialContext(props);
// System.out.println("ok");
// HelloWorld helloworld = (HelloWorld) cts.lookup("HelloWorldBean/remote");
// System.out.println(helloworld.sayHello("帅哥"));
// }catch(Exception e){
// e.printStackTrace();
// }
}
}
屎都运行不出来........
报错代码如下
2013-2-17 15:56:23 org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 1.0.5.Final
ejb:/HelloWorld//HelloWorldBean!cn.itcast.ejb3.HelloWorld
ok
2013-2-17 15:56:23 org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration createConnectionConfiguration
INFO: No port configured for connection named default. Skipping connection creation
java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@defa1a
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 cn.itcast.test.EJBClient.main(EJBClient.java:34)
求解......