ejb2.0 开发实例

组件接口类

public interface Hello extends EJBObject{
public String getHello() throws RemoteException;
}

主接口类一般命名为xxxHome

public interface HelloHome extends EJBHome {
public Hello create() throws RemoteException,CreateException;
}

实现类一般命名为xxxEJB

public class HelloEJB implements SessionBean {
public void ejbActivate() throws EJBException, RemoteException {
}
public void ejbPassivate() throws EJBException, RemoteException {
}
public void ejbRemove() throws EJBException, RemoteException {

}

public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
}

public void ejbCreate() throws javax.ejb.CreateException {
}

public String getHello() {
return "Hello!EJB ";
}
}

ejb-jar.xml


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version="2.1">



Generated by XDoclet







Name for Hello

Hello


com.eric.interfaces.HelloHome



com.eric.interfaces.Hello



com.eric.ejb.HelloEJB

Stateless
Container






jboss.xml




Hello
ejb/Hello



HelloHome home=null;
String result=null;
Properties props = new Properties();
props.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url", "localhost:1099");
props.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
InitialContext ctx = new InitialContext(props);
home=(HelloHome)ctx.lookup("ejb/Hello");
Hello hello = home.create();
result = hello.getHello();

你可能感兴趣的:(J2EE)