标签:
1. new EJB project
2.创建一个 sessionbean 接口
3.编写ejb接口
package com.mo.ejb; import javax.ejb.Stateless; @Stateless public interface HelloWorld { String sayHello(String name); }
4.实现接口
package com.mo.ejb; public class HelloWorldImpl implements HelloWorld { public String sayHello(String name) { return name+" hello world"; } }
1.创建 java project HelloworldClient,添加对上面HelloWorld.jar的引用和JBOSS Client的jar包($JBOSS_HOME/clent/jbossall-clent.jar),添到ClassPath路径下。
2.编写 client 调用程序
import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.mo.ejb.HelloWorld; public class Client { public static void main(String[] args) throws NamingException { InitialContext initialContext = new InitialContext(); Properties p = new Properties(); // p.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory"); p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory"); p.put(Context.PROVIDER_URL,"localhost:"); HelloWorld ejb = (HelloWorld) initialContext .lookup("HelloWorldImpl/remote"); String name = ejb.sayHello("大哥"); System.out.println(name); } }
未完待续。。。
标签:
原文地址:http://www.cnblogs.com/yun965861480/p/5961405.html