Introduction to the configuration and deployment of EJB in JBoss3.0

zhaozj2021-02-16  52

1. Introduction to JBoss

JBoss is a J2EE application server running EJB. It is an open source project and follows the latest J2EE specification. From the JBoss project, it has developed from an EJB container into a web operating system based on J2EE, which reflects the latest technology in the J2EE specification, and it is also in the JavaWorld Editors' Choice 2002. Get the "Best Java Application Server" award in the selection. Whether it is learning or applying, JBoss provides us with a very good platform. For more information on jboss, please refer to its homepage http://www.jboss.org.

When you start using JBoss for EJB development, it is more difficult to start. JBoss configuration and use does not provide a graphical wizard interface, so develop deployment EJB is relatively complicated. This article makes a simple introduction to the EJB development and deployment of JBoss3.0 as much as possible, so that users who have just started using JBoss can quickly enter the real J2EE application development.

Since this paper introduces the configuration and deployment of different types of EJB in JBoss 3.0, there is no more description of basic EJB development, so I hope the reader has J2EE and EJB experience. For information, please refer to the reference 1.

2. Basic EJB Configuration and Deployment in JBoss3.0

According to the J2EE specification, a basic EJB JAR package is used by EJB-JAR.XML. WAR package for web applications is web.xml. Application.xml is used by the EAR package of an enterprise application. These profiles are neutralized and platform-independent. Simultaneous application servers can use some other configuration files to describe information about a particular server. Such files in JBoss have JBoss.xml, JBoss-Web.xml, etc. These files in the JBOSS container are not required. If it is provided, jboss.xml and ejb-jar.xml are placed in the same directory, JBoss-web.xml and web.xml are placed in the same directory. For references to JBoss.xml and JBoss-Web.xml, please refer to the corresponding DTD file in the DOCS / DTD / directory in the JBoss installation directory.

2.1 Configuration for EJB Clients in JBoss:

Calling EJB clients can be JSP, servlet, or client applications. If the client and server are not on the same Java VM, then the client must provide a JNDI.Properties file telling the client to perform information about the JNDI naming service, and set the directory where the file is located to the environment variable ClassPath.

The following is a case: Sample of JNDI.Properties:

Java.naming.factory.initial = org.jnp.interfaces.namingContextFactory

Java.naming.Provider.URL = localhost: 1099 (server address and port number)

Java.naming.factory.url.pkgs = org.jboss.naming: Org.jnp.interfaces

Through this file and some client class libraries of JBoss, you can use the EJB object service provided by JBoss.

2.2 JBOSS deploy EJB:

First introduce two methods of deploying various EJB objects in the JBoss container. The following demonstration is as an example of Session Bean, the client is a web application on this unit. This is not specifically described here.

The first way:

Put the WAR package of developing EJB JAR packets and web applications in a deploy directory.

Demonstration 1: No jboss.xml files and any other special settings.

EJB-jar.xml:

······

EJBTEST

······

Client: Web application does not need to add EJB information for web.xml, no JBoss-web.xml file. The JSP files of the reference EJB object are as follows:

······

InitialContext CTX = New InitialContext ();

Object objref = ctx.lookup ("ejbtest"); // uses beanhome = (zcxejb1home) PortableRemoteObject.narrow (Objref, EjbTestHome.Class);

······

Demo 2: Use the jboss.xml file.

The JBoss JNDI service will use XXX's Home Interface in XXX XXX in EJB-JAR.XML. But if there are multiple EJB objects in the same EJB JAR package, in ejb-jar.xml via XXX , it may not be good to represent a EJB object, so usually It is desirable to provide some additional information, such as using such formats "[App Name] / [Bean Name]" to reference an EJB object. At this time, JNDI service may not find your EJB object correctly, we need to use JBoss.xml files, achieve the redirection of JNDI names to EJB names. This file must be placed in the Meta-Info directory with EJB-JAR.XML.

EJB-jar.xml:

······

EJBTEST

······

JBoss.xml:

EJBTEST

EXAMPLE / EJBTEST

Client: You need to use the new JNDI name for EJB positioning.

······

InitialContext CTX = New InitialContext ();

Object objref = ctx.lookup ("eXample / ejbtest"); // uses beanhome = (zcxejb1home) PortableRemoteObject.narrow (Objref, EJBTESTHOME.CLASS);

······

The second way:

Pack the EJB and web applications into an enterprise application package. When deploying EAR, you can simply describe the WAR package of the EJB JAR package and web apparatus via Application.xml, and you can use the EJB object as in the first way without providing special information in Web.war. The client code does not need to be changed. Next, it will not be exemplified here.

In addition, we can make a further deployment, and we need to use Web.xml and JBoss-Web.xml. JBoss-Web.xml is a file provided by JBoss to web applications. JBoss-Web.xml and Web.xml are placed in a web-inf directory of the web application.

Demonstration 1: Change the web.xml file, add tag, and do not use the JBoss-Web.xml file.

(Note includes internal reference and external reference. If it is the same unit, you can use to directly reference, without providing additional information.) Web.xml:

······

EJB / EJBTEST

Session

Org.zcx.test.zcxejb1home

Org.zcx.test.zcxejb1

EJBTEST

······

Client: Due to the introduction of EJB reference in Web.xml, the EJB positioning changes:

······

InitialContext CTX = New InitialContext ();

Object objref = ctx.lookup ("java: comp / ENV / EJB / EJBTEST"); // Using Java: Comp / Env Name Space Beanhome = (ZCXEJB1HOME) PortableRemoteObject.narrow (Objref, EJBTESTHOME.CLASS);

······

Demonstration 2: Joint Using Web.xml and JBoss-Web.xml

Web.xml

······

EJB / EJBTEST

Session

Org.zcx.test.zcxejb1home

Org.zcx.test.zcxejb1

······

JBoss-web.xml

EJB / EJBTEST

EXAMPLE / EJBTEST

Client:

NitialContext CTX = New InitialContext ();

Object objref = ctx.lookup ("java: comp / eNV / EJB / EJBTEST"); beanhome = (zcxejb1home) PortableRemoteObject.narrow (Objref, EJBTESTHOME.CLASS);

All of the above demonstrations illustrate the basic relationship between EJB-JAR.XML, JBOSS.XML, Web.xml, JBoss-Web.xml and their usage. They are key files for deploying various EJB objects. Next, introduce the special configuration required for different types of EJB objects.

3. Configuration for CMP2.0 Entity Beans in JBoss3.0

The JBoss 3.0.0 JBossCMP engine implements EJB2.0 CMP2.0 specification. JBoss3.0 Previous version CMP engine is JAWS, which is configured via Standardjaws.xml and Jaws.xml. JBoss3.0 in the new JBossCMP engine configures Entity Bean through StandardJbosscmp-JDBC.XML and JOSSCMP-JDBC.xml. JBoss3.0 processes StandardJBossCMP-JDBC.XML and then provides further processing based on whether jbosscmp-jdbc.xml is provided in EJB JAR. With StandardJBossCMP-JDBC.XML and JBossCMP-JDBC.XML, you can provide the following features for Entity Beans: l Specify the data source used and the corresponding type mapping.

l Specify some attributes of some engines

l How to specify how the engine creates and manages database tables

l Describe the Finder and EJBSELECT methods

l Specify the type mapping of the properties and fields

Here mainly describes the configuration method of CMP2.0 according to StandardJbosscmp-JDBC.XML / JBOSSCMP-JDBC.XML. The original JAWS engine in JBoss is similar to the new JBossCMP configuration method. The specific information of these files can refer to the corresponding DTD file in the / DOCS / DTD in the JBoss installation path.

3.1 Adding new data sources

The JBoss comes with the database is a Hypersonic database, we can add some new data sources. The specific steps are simple, with reference to the * -service.xml file in the DOCS / Examples / JCA in the JBoss installation directory, you can add a database configuration sample file to find the corresponding type. Take the mysql-service.xml file as an example, it can configure a MySQL database as the data source of the Entity Bean. The following demo creates a MySQL data source called mysqlds.

Figure 1 is a code sample for configuring a good mysql-service.xml file, and the name of the data source can be customized by attribute settings and other properties of the connection. Note that all NAME properties in this file must be consistent.

Figure 1 mysql-servic.xml sample code

After configuring this file, deploy it in the DEPLOY directory of jboss, put the corresponding JDBC driver in the lib directory. Restart JBoss will load this new data source.

3.2 Entity Bean Use the data source

The first way:

Change StandardJbosscmp-JDBC.XML directly. Shield the original data source Java: / defaultLDS to use the new data source java: / mysqlds. (The Java prefix is ​​required.) Do not need to be changed elsewhere. JBoss will implement new data sources as the default data source. Figure 2 is a configured file piece.

Figure 2 Sample code for STANDARDJBOSSCMP-JDBC.XML

The second way:

Since there is a possible different Entity Bean to use different data sources, instead of using the same default configuration, you must provide a separate Entity Bean support for custom data source information. At this time, you don't need to change the StandardJbossCMP-JDBC.xml file, you can do it by adding a new deployment file jbosscmp-jdbc.xml in the meta-info directory in the Entity Bean. Through this file, you can describe the configuration information about the data source for the specific Entity Bean. Figure 3 is a piece of configured file.

Figure 3 JBossCMP-JDBC.XML sample code

4. Configuration for Message Driven Bean in JBoss3.0

Developing MDB in JBOSS requires JMS functionality. JMS is a message-oriented middleware API developed by Sun. Its primary purpose is to create a unified JavaAPI for message-oriented, thus avoiding the use of a specific API. There are now several different JMS systems available. JBoss3.0 is provided in JBossmq. 4.1 Configuring JMS services in JBoss3.0

Profiles related to JMS service in JBoss3.0 include two files: jbossmq-service.xml and jbossmq-destinations-service.xml. JBossMQ-Service.xml is configured with core object information in the JBOSSMQ service. Generally we do not need to handle this configuration file. JBossMQ-DestinationS-Service.xml is used to define the destination information required for the specific application. By editing it we can create new Topic and Queue for specific JMS applications for specific JMS applications. Creating a specific Topic and Queues in JBoss is relatively simple, refer to the jbossmq-detentinations-service.xml file format to add your own application to the Topic called MyTestAppTopic and Queue named myTestAppQueue. As shown in Figure 4.

Figure 4 JBossMQ-DestinationS-Service.xml sample code

4.2 JBoss3.0 in EJB Configuration of JMS Services

In developing MDB, you should specify the destination information in the JMS service used in the deployment file. JBOSS is used through EJB-JAR.XML and JBOSS.XML. Describe the destination information used via the tag in jboss.xml.

Ejb-jar.xml

HellotopicMDB

Org.zcx.test.HellomDB

Container

javax.jms.topic

Nondurable

Jboss.xml

HellotopicMDB

Standard Message Driven Bean

Topic / myapptesttopic

Client:

······

Context context = new initialContext ();

// Get the connection factory

// Create The Connection

// Create the session

······

// Look Up The Destination

Topic = (Topic) Context.lookup ("Topic / MyTestApptopic"); // Create a Publisher

// Publish The Message

······

5. EJBs in JBoss3.0 use the configuration of the JavaMail service.

Since JBoss provides the implementation of the JavaMail service, it is very convenient to use JavaMail in JBOSS. What it needs to be configured is a mail.service file. This file is very easy to introduce more. Follow the annotations of the mail.service file to complete the configuration.

Figure 5 is a session piece of a sessionbean using JavaMail service.

Figure 5 Sample code using JavaMail

The above introduces the most basic configuration and deployment methods of session beans in JBoss 3.0.0 in JBoss 3.0.0, which can now be developed in JBOSS. In this paper, there are no more complex configuration rights settings in EJB applications, and many configurations in the resource management and CMP2.0 are not involved. I hope everyone can better master the use and configuration of JBoss in constant practice and communications. .

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

New Post(0)