The development tool is IBM RAD 7.5.4.
was version 6.1.
EJB version 2.0.
Development process as shown:
After the new construction, the engineering structure is as follows:
and new Sessionbean.
Next
Complete.
As shown in figure:
Modify several files:
Package COM.EJB;
Import static java.lang.System.out; /** * Bean implementation class for Enterprise bean:hellosession/public class Hellosessionbean implements.
Sessionbean {static final long serialversionuid = 3206093459760846163L;
Private Javax.ejb.SessionContext Mysessionctx;
/** * Getsessioncontext * * public javax.ejb.SessionContext Getsessioncontext () {return mysessionctx;
}/** * Setsessioncontext/public void Setsessioncontext (Javax.ejb.SessionContext ctx) {mysessionctx = CTX;
}/** * Ejbcreate/public void Ejbcreate () throws Javax.ejb.CreateException {out.println ("ejbcreate");
}/** * Ejbactivate/public void Ejbactivate () {out.println ("ejbactivate");
}/** * Ejbpassivate/public void Ejbpassivate () {out.println ("ejbpassivate");
}/** * Ejbremove/public void Ejbremove () {out.println ("Ejbremove");
public string SayHello (string someOne) {out.println ("SayHello"); Return "Hello, "+ SomeOne +"! ";}}
Package COM.EJB;
Import java.rmi.RemoteException;
/**
* Remote interface for Enterprise bean:hellosession/public
interface hellosession Javax.ejb.EJBObject {public
string SayHello (String someOne) throws remoteexception;
}
Add a test class:
Package COM.EJB;
Import java.rmi.RemoteException;
Import java.util.Properties;
Import javax.ejb.CreateException;
Import Javax.naming.Context;
Import Javax.naming.InitialContext;
Import javax.naming.NamingException;
Import Javax.rmi.PortableRemoteObject; public class TestClient {/** * @param args * @throws namingexception * @throws createexception * @throws Remote Exception */public static void main (string[] args) throws Namingexception, RemoteException, createexception {Pro
Perties props = new Properties ();
Props.setproperty (Context.initial_context_factory, "com.ibm.websphere.naming.WsnInitialContextFactory");
Props.setproperty (Context.provider_url, "iiop://127.0.0.1:2810/");
Context ctx = new InitialContext (props);
Object ObjRef = Ctx.lookup ("Ejb/com/ejb/hellosessionhome");
Hellosessionhome home = (hellosessionhome) portableremoteobject.narrow (ObjRef, Hellosessionhome.class);
hellosession Hello = home.create ();
String msg = Hello.sayhello ("EJB");SYSTEM.OUT.PRINTLN (msg);
}
}
The name of the Jndi above, which can be found in Ibm-ejb-jar-bnd.xmi, contains:
<?xml version= "1.0" encoding= "UTF-8"?> <ejbbnd:ejbjarbinding xmi:version=
"2.0" xmlns:xmi= "http:/"
/www.omg.org/xmi "xmlns:ejb=" Ejb.xmi "xmlns:ejbbnd=" Ejbbnd.xmi "xmi:id=" ejbjarbinding_1393691689296 "
>
<ejbjar href= "meta-inf/ejb-jar.xml#ejb-jar_id"/>
<ejbbindings xmi:id= "Enterprisebeanbinding_" 1393691689296 "
jndiname=" Ejb/com/ejb/hellosessionhome ">
<enterprisebean xmi:type=" Ejb:Session "
href= "meta-inf/ejb-jar.xml#hellosession"/>
</ejbBindings>
</ejbbnd:EJBJarBinding>
Ejb-jar.xml content:
<?xml version= "1.0" encoding= "UTF-8"?> <ejb-jar id=
"ejb-jar_id" >
<display-name>ejb</ display-name>
<enterprise-beans>
<session id= "hellosession" >
<ejb-name> hellosession</ejb-name>
The contents of the two files above are automatically generated without modification. If you know how to change, you can change it.
Then add Ejbsystem to the WAS6.1, start was, and generate some Java files, as shown in figure:
At this time, run TestClient, will complain, the solution, see http://blog.csdn.net/feier7501/article/details/20247219
The above problem, after resolving, can be tested successfully. The port in the above URL, is generally 2809, I am here is 2810. Anyway, it's starting from 2809, plus 1.
Service-Side output:
[14-3-2 0:44:04:890 CST] 00000041 systemout o ejbcreate
[14-3-2 0:44:04:906 CST] 00000041 systemout o SayHello
Client output:
Hello, ejb!.