Easy writing EJB components using EJBFrame

zhaozj2021-02-17  52

EJB (Enterprise Java Bean is the core technology in J2EE, defining enterprise-level application components specifications. The development of the application system of the 3-layer structure is achieved by encapsulating the business logic in the EJB assembly.

However, the EJB specification is relatively complicated, and writes EJBs to write EJB's HOME interface, Remote interface, and EJB implementation classes. The EJB specification has made many of these interfaces and classes, and it is very inconvenient to handle and easily errors. Here, I recommend a tool to everyone, EJBFrame. EJBFrame is a tool for generating the EJB component framework source program provided by MiniJ2EE. You can automatically generate the correct EJB HOME interface, EJB Remote interface, and EJB implementation classes through the GUI interface operation, and can also generate access databases, access the URL Resources, send and receive mail code. You only need to fill the generated code, add your business logic to easily complete the writing of EJB components.

Before you introduce how to use EJBFrame, we will briefly review the basic knowledge of EJB. In EJB Specification 1.1, EJB is divided into three types of Enterprise Beans, Stateful Session Bean, Stateless Session Bean, and Entity Beans. For each EJB, the HOME interface defines the method of creating and looking for EJB; the Remote interface defines the business logic method of EJB; EJB classes need to implement methods corresponding to the HOME interface and Remote interface, these methods will be called by EJB Container to provide customers Request for EJB. With regard to the writing method of the EJB Home interface, the Remote interface, and EJB classes, you can see the MINIJ2EE's user manual (http://www.minij2ee.com/document/), there is a detailed description. Here, what we want to introduce how to use EJBFrame to easily generate EJB framework code.

We develop a simple STATEFUL SESSION bean as an example to demonstrate how to use EJBFrame. Our demonstration EJB only provides a GetHelloWorld method, returns a string of "Hello World from EJB!". At present, EJBFrame tools need to run on Windows (http://www.minij2ee.com/download/), support Linux version is being developed.

We start the EJBFrame program, enter the main interface of EJBFrame, and then do the following: 1. Specify the name of the EJB Remote interface: Enter the name of the EJB Remote interface in the Remote Interface Name box in EJB Information, here our EJB is Hello, input Hello. After the input, the EJBFrame tool automatically generates the name of the EJB HOME interface as HelloHome. The name of the EJB class is Helloejb. The name of the EJB is-HelloException, EJB-jar.xml is specified in EJB-jar.xml. Value) is Hellobean.

2. Select EJB Type: Select Session in EJB Type in EJB Information, because our EJB is Session Bean.

3. Add a method for the REMOTE interface: As mentioned above, our EJB provides a GetHelloWorld method. Press the Add Method dialog in Remote Interface Methods. In the Add Method dialog box, returniting selects String, enters GetHelloWorld in Method Name, press OK. The addon code area in the Add Method dialog is used to select additional code generated by this method. Checking Database to generate a database access code. Checking POP3 will generate a code that charges Email. Select the SMTP to generate the code that sends mail, select the URL to generate access The code of the URL resource. Since our EJB is relatively simple, you don't need to generate additional code 4. Adding a method for the Home interface: We need to add a CREATE method for the HOME interface for EJBs to create an EJB object. Press the Add Method dialog in Press the Add Method dialog in Home Interface Methods. In the Add Method dialog box, Method Type selects Create Method, enter Create in Method Name, press OK.

5. Generate the EJB Framework code According to the Generate button on the main interface, a DOS window will appear, show: Done! Press any key. At this time, hello.java, helloejb.java, helloejb.java, helloexception.java will be generated in the current directory.

6. Open the completion code HelloEJB.java, modified public String getHelloWorld () throws HelloException follows: public String getHelloWorld () throws HelloException {return "hello world from EJB!";} Then, at run javac * .java directory. Finally, hello.class, hellohome.class, helloejb.class, and helloException.class. In this way, an EJB is completed.

Some common problems are listed below, if there is a problem in the operation in the steps, please refer to. * No successful screen appears after pressing the Generate button. .

* Javac compile code error 1. Check if minij2ee.jar and mail.jar are in ClassPath, the two files in the lib sub-directory of the Minij2ee directory. 2. Please check the program code.

More technical documents, all in the Minij2ee Technical Document Center, please visit http://www.minij2ee.com/document/.

转载请注明原文地址:https://www.9cbs.com/read-29254.html

New Post(0)