Environment:
JBoss 4.0.2
JDK1.5
IDEA8.1.4
First, EJB development
Package lavasoft.testejb20yzt;
Import Javax.ejb.SessionBean;
Import Javax.ejb.SessionContext;
/**
* Bean class
* All specific business logic is in this class, this class does not throw remote heterogeneous
*
* @author leizhimin 2010-3-31 15:26:53
*/
public class Hellostatefulbean implements Sessionbean/
Private Sessioncontext context;
Private String SomeOne;
/**
* Business Approach
*
* @return The News of Hello
*/
Public String SayHello ()/
System.out.println ("Hellostatefulbean:sayhello () is called!");
Return "Hello," + SomeOne + "!";
}
/**
* Must have this method, this is a principle of EJB, this method does not come from the Sessionbean interface
* This can only be a stateful bean, because a stateless bean cannot have other creation methods other than the no-parameter create method
*/
public void Ejbcreate (String someOne)/
System.out.println ("Hellostatefulbean:ejbcreate (String someOne) is called!");
This.someone = SomeOne;
}
-------The following four methods are from Sessionbean, which must be written out, but it is of no use-------
public void ejbactivate ()/
System.out.println ("Hellostatefulbean:ejbactivate () is called!");
}
public void ejbpassivate ()/
System.out.println ("Hellostatefulbean:ejbpassivate () is called!");
}
public void Ejbremove ()/
System.out.println ("Hellostatefulbean:ejbremove () is called!");
}
public void Setsessioncontext (Sessioncontext sessioncontext)/
System.out.println ("Hellostatefulbean:setsessioncontext () is called!");
context = Sessioncontext;
}
}
Package lavasoft.testejb20yzt;
Import Javax.ejb.EJBObject;
Import java.rmi.RemoteException;
/**
* Component Interface
* All business methods must be declared in this interface
*
* @author leizhimin 2010-3-31 15:31:10
*/
Public interface Hellostateful extends Ejbobject/
/**
* Business method, the business method in the component interface must throw RemoteException
*
* @return
* @throws java.rmi.RemoteException
*/
Public String SayHello () throws remoteexception;
}