Developing Stateless Session Beans with Rational Application Developer
Prepare the development environment by following the steps below.
-> Create a new EAR Project
-> Add EJB Project, Web Project and EJBClient Project
Creating New Session Bean
Expand Deployment Descriptor of the EJB Project and select Session Beans
Right click and create new Session Bean
-> Select "Session Bean"
-> Provide a Bean name
-> Check "Generate an annotated bean class"
-> Next
-> Select Session type "Stateless"
-> Select Transation type "Container"
-> Check "Remote Client View"
-> Finish
Implementing And Promoting New Methods
-> Implement methods in the newly created session bean
-> Right click the methods
-> Select Enterprise Beans
-> Click "Promote to Remote Interface"
Preparing for Deployment
-> Right click the deployment descriptor
-> Select "Prepare for Deployment"
Configuring Web Application
Open the deployment descriptor of the Web Application
Select References tab
Click "Add..." to add a new reference
-> Select "EJB reference"
-> Browse the projects and select the ejb to add
-> Select the RefType as Remote
Make sure the name of the Reference is same as the last two portions of the COMP_NAME of the Home Interface ( for eg. if COMP_NAME = "java:comp/env/ejb/TestBean"; then RefName = ejb/TestBean )
Creating and Using the EJB
Example
try {
TestHome testH = TestBeanUtil.getHome();
Test test = testH.create();
}catch(Exception exp) {
exp.printStackTrace();
}
Classloader Settings
Set the classloader as "Application" instead of "Module" for the Enterprise application
No comments:
Post a Comment