1.TradeBean.java 代码如下:
import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; /** * XDoclet-based session bean. The class must be declared * public according to the EJB specification. * * To generate the EJB related files to this EJB: * - Add Standard EJB module to XDoclet project properties * - Customize XDoclet configuration for your appserver * - Run XDoclet * * Below are the xdoclet-related tags needed for this EJB. * * @ejb.bean name="Trade" * display-name="Name for Trade" * description="Description for Trade" * jndi-name="ejb/Trade" * type="Stateless" * view-type="both" */ public class TradeBean implements SessionBean { /** The session context */ private SessionContext context; public TradeBean() { super(); } public void ejbCreate() throws EJBException{ System.out.println(" ejb create "); } public void ejbActivate() throws EJBException, RemoteException { System.out.println(" ejb activate "); } public void ejbPassivate() throws EJBException, RemoteException { System.out.println(" ejb passivage "); } public void ejbRemove() throws EJBException, RemoteException { System.out.println(" ejb remove "); } /** * Set the associated session context. The container calls this method * after the instance creation. * * The enterprise bean instance should store the reference to the context * object in an instance variable. * * This method is called with no transaction context. * * @throws EJBException Thrown if method fails due to system-level error. */ public void setSessionContext(SessionContext newContext) throws EJBException { System.out.println(" set session context "); context = newContext; } public String sayHello() throws RemoteException{ return "Welcome to EJB2.0,HXL"; } }
2.TreadeBeanHome.java 程序如下:
import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface TreadeBeanHome extends EJBHome { TreadeBeanRemote create() throws RemoteException,CreateException; }
3.TreadeBeanRemote.java 程序如下:
import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface TreadeBeanRemote extends EJBObject { String sayHello() throws RemoteException; }