Prerequisites
The
Windows
®
Open Perspective
®
Other
®
J2EE
perspective is open.
Procedure
Creating the EJB Module Project
You develop the EJB 3.0 classes in an EJB 3.0 project in the J2EE perspective.
...
1.
Choose File
®
New
®
Project from the main menu.
2.
Select the EJB Project 3.0 wizard by choosing EJB
®
EJB Project 3.0 on the New Project screen.
3.
Choose Next to proceed to the Create an EJB 3.0 Project screen.
4.
Enter
ConverterEJB
in the Project Name field.
5.
Leave the Create project in the workspace for the Location of the project.
6.
To assign the EJB project to an Enterprise Application project, choose Add project to an EAR and enter
ConverterEAR
in EAR Project Name field.
The ConverterEAR project is created automatically when you complete the wizard.
7.
Choose Finish to create your EJB 3.0 project.
Creating the Stateless Session Bean
...
1.
From the context menu of the ejbModule node of the ConverterEJB project choose New
®
Other.
2.
Choose EJB
®
EJB Session Bean 3.0 on the New screen.
3.
Choose Next.
4.
Enter ConverterBean in the EJB Name field and com.sap.tutorial.javaee in the Default EJBPackage field.
5.
Select the Stateless radio button for Session Type.
6.
Deselect the Remote checkbox for Create Interface.
7.
Choose Finish.
8.
Implement the business logic of
ConverterBean
by entering the following code in its body:
private
BigDecimal dollarRate =
new
BigDecimal(
"1.2"
);
private
BigDecimal euroRate =
new
BigDecimal(
"0.83"
);
public
BigDecimal dollarToEuro(BigDecimal dollars) {
BigDecimal result = dollars.multiply(euroRate);
return
result.setScale(2, BigDecimal.ROUND_UP);
}
public
BigDecimal euroToDollar(BigDecimal euros) {
BigDecimal result = euros.multiply(dollarRate);
return
result.setScale(2, BigDecimal.ROUND_UP);
}
|
9.
To import the additional classes that you refer in your code, choose Source
®
Organize Imports from the main menu.
10.
To add the
dollarToEuro
business method to the bean’s local interface, locate the
Outline
view and from the context menu of the method choose
EJB Methods
®
Add to Local Interfaces
.
Repeat the same step to add the
euroToDollar
method to the local interface as well.
11.
Choose File
®
Save from the main menu to save the bean.
本文转自 牛海彬 51CTO博客,原文链接:http://blog.51cto.com/newhappy/77027,如需转载请自行联系原作者