Stateless Session BeanBelow example is demostration of converting Currency from dollar to rupees, euro, pond, yen or rubble.
The following components are used :
- Component (Remote) Interface - Defines the client view of the Bean and corresponding business methods for remote client (different JVM).
- Component (Local) Interface - Defines the client view of the Bean and corresponding business methods for local client (same JVM). [ You deploy EJB (.jar) and web (.war) in the form of .ear on Application Server ]
- Bean Class - It must contain the bean callback methods, implementation of Component (Remote/Local) interface methods and any optional life-cycle methods.
[ Note : No need Deployment descriptor EJB Configuration XML file ]
Below steps are to create Stateless session bean :
- Install Oracle WebLogic Server 10.3.2
- Create Domain on Orcale WebLogic Server 10.3.2
- Configure Domain in Eclipse
- Create Enterprise Application StatelessDemo1.ear.
- Create Stateless Bean Local interface in EJB project
- Create Stateless Bean class in EJB project
- Create index.jsp in Web project
- Create Servlet in Web project
- Run the Application
Step 1: Install Oracle WebLogic Server 10.3.2 [ Click here - How to install WebLogic Server ]
Step 2: Create Domain on Orcale WebLogic Server 10.3.2 [ Click here - How to create Domain on WebLogic Server ]
Step 3: Configure Domain in Eclipse [ Click here - How to Configure Domain in Eclipse ]
Step 4: Create Enterprise Application StatelessDemo1
File -> New -> Enterprise Appliction Project :
Specify the Enterprise Project name StatelessDemo1 and click Next.
Below screen is used to create EJB and Web module in Enterprise Application project. Click New Module :
Check EJB Module and Web Module and Click Finish :
You will get below screen and again click Finish :
This step will create Enterprise project with EJB and Web project.
Step 5: Create Stateless Session Bean in EJB project
Right click on EJB project -> New -> Session Bean (EJB3.X) :
Specify the below information and click Next:
Java Package : techmyguru.stateless
Class name : SessionConcerter
State Type : stateless
Local : techmyguru.stateless.SessionConverterLocal
Verify the information and click Finish
This step will create two java file. One will be local interface SessionConverterLocal.java and other will be bean class SessionConverter.java.
Edit bothe class java file as below :
Step 7: Add EJB Project to Web project
Right Click on Web Project - > Properties - > Java Build Path -> Click Projects -> Add -> Select StatelessDemo1EJB.
Step 8: Create index.jsp in Web project
Step 9: Create Servlet Servlet1.java in Web project
Step 10: Verify the directory structure
Step 11: Run the Application
Right click on Web Project -> Run As -> Run on Server
You will get below output :
Enter the number of dollar and select the desired currency type in which you want to convert and click Convert .
You will get below output :
|Previous||Download Source Code||Next|
|Comment by : Juan||October 3rd, 2015|
|Comment : Excellent read. I just passed this onto a buddy who was doing a lttlie research on that. He just bought me lunch since I found it for him! Thus let me rephrase: Thank you for lunch!|
|Comment by : Sudhir||February 19th, 2015|
|Comment : Hi, Many thanks for the lovely tutorial. Unfortunately null pointer exception is coming up at line where bean method is accessed. Do we need to use any JNDI lookup?? Please help out.|
|Comment by : Ahmed||October 22nd, 2012|
|Comment : I want to check the url content please|
|Comment by : shilpa||October 22nd, 2012|
|Comment : need ejb3|