日期:2014-05-20 浏览次数:20740 次
HelloEJBRemote.java
package com.service;
import javax.ejb.Remote;
@Remote
public interface HelloEJBRemote {
public String RemoteSayHello(String name);
}
HelloEJB.java
package com.service;
import javax.ejb.Local;
@Local
public interface HelloEJB {
public String sayHello(String name);
}
HelloEJBImpl.java
package com.serviceImpl;
import javax.ejb.Stateless;
import com.service.HelloEJB;
import com.service.HelloEJBRemote;
@Stateless
public class HelloEJBImpl implements HelloEJBRemote,HelloEJB {
@Override
public String sayHello(String name) {
return name+" say:HelloEJB";
}
public String RemoteSayHello(String name) {
return name+" (Remote)say:HelloEJB";
}
}
EJBClient.java
package com.client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.service.HelloEJBRemote;
public class EjbClient {
public static void main(String[] args) throws NamingException {
Context ctx = new InitialContext();
HelloEJBRemote he = (HelloEJBRemote)ctx.lookup("HelloEJBImpl/remote");
System.out.println(he.RemoteSayHello("张三"));
}
}