Method of deploying EJB components of Java on server side

What is EJB? EJB is a Java enterprise bean and a Java EE service-side enterprise component model. Its design goal and core application is to deploy distributed applications. Without much to say, let's look directly at how to deploy EJB3 locally. Deployment environment: operating system: Windows 8.1 EJB Container: JBoss 7.1 DB: MySQL 5.6 10 ide: MyEclipse 10 JDK: 1.6 1. Create a database and table. Because you need to communicate with the database in this process, you need to create a database table first. Create database:

Create table:

Establish operation interface:

The interface has only one method to get all students to establish session beans

3. The data source configuration here needs to be noted that the configuration of jboss6 and jboss7 is different. Both JBoss 6 and previous versions add * * - DS. In the deploy directory XML, where * * represents any database name. If it is mysql, it is MySQL DS XML file. In JBoss 7, it is different. Switch the directory to the JBoss installation directory,% JBoss_ Under home%, enter the modules / COM directory, create the folder MYSQLDATABASE, enter, create the MySQL folder, enter, create the main folder. In the main directory, create module XML file. The content of the configuration file is:

In particular, it should be noted that the value of the module node attribute name is the path of the folder we just created. Resources represents the path of the MySQL driver. This means that you need to put the driver of MySQL in the main directory. That is, the main directory contains two files, module XML and database driver files. After completing the previous step, switch to% JBoss_ In the home% \ standalone \ configuration directory, open standalone XML, search datasources, and configure as follows

JNDI name represents the JNDI name of the data source, and connection URL represents the URL string of the connection; The 3306 port is used by default. The student library is used. The user name and password are configured in the first step. Module configuration is the path of the module just configured. The related configuration of JBoss has been completed, and then switch to the newly created project, including a persistence XML configuration file, which is configured as follows, where JTA data source is the JNDI name configured above

So far, the server code and data source configuration have been completed. The next thing you need to do is how to deploy the code and how to call the EJB service on the client. 4. Deploy EJB services. Print all the code written in the project into a jar package and name it ejbservice jar。 At the same time, only entity beans and interfaces are packaged into jar packages, named ebjinterface Jar, which will be used for client calls in the future. Set ejbservice Jar into% JBoss_ Home% \ standalone \ deployments directory. When JBoss starts, it will automatically scan the directory. Then deploy the jar. OK, we configure JBoss under MyEclipse, start JBoss in MyEclipse, and observe the output of the console. If the deployed "ejbservice. Jar" log appears, the EJB deployment is successful. 5. How does the client call it? The client call requires two prerequisites: introducing JBoss EJB client Properties configuration, JBoss client Jar and ejbininterface jar。 Where JBoss client Jar is located in JBoss bin / client directory. ejbinterface. Jar is the interface jar package that we just created for the client. jboss-ejb-client. The properties configuration is as follows:

With these two conditions, you can safely create a test class ejbtest Java, write the client method.

Run this code, you can successfully query the data in the database. At this point, EJB deployment is successful.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>