Download presentation
Presentation is loading. Please wait.
Published byClaire Cain Modified over 9 years ago
1
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li lu.li@liu.se
2
Agenda EJB brief introduction Practical hints
3
Why EJB EJBs is a powerful component model for building distributed, server-side, and Java- based enterprise application components. Code reuse by middleware service, such as object life-cycle management, resource (beans, database connection) mapping etc.
4
EJB architecture
7
Connect Glassfish to Database Configure MySQL database Copy driver to Glassfish directory Configure a connection pool (For example “TDDD05_MySQL”), and do a ping test Configure JDBC resource (For example “TDDD05_JDBC”) to use the connection pool (“TDDD05_MySQL”)
8
Create an JPA to use database JPA is a kind of EJB for interaction with database. Configure persistence.xml under META-INF folder, if no such xml file found, create one.
9
Create an Stateless Bean Create a EJB project Add library appserv-rt.jar, j2ee.jar
10
Create an Stateless Bean Create an interface
11
Create an Stateless Bean Create an implementation
12
Deploy EJB Export jar Start Glassfish Copy jar file into the autodeploy directory Check the file generated There is another way to deploy. (Covered later)
13
JNDI lookup
14
JNDI Application
15
Dependency injection
16
DI Application
17
Deployment (Glassfish_Home)/bin/asadmin deploy – retrieve. Ex1-ee.ear Execution (Glassfish_Home)/bin/Appclient –client./ex1- eeClient.jar –mainclass client.AppClient
18
Facade
19
Summary You needs a MySQL with a designed table. You needs to make a Glassfish to know the connection to your MySQL You needs a JPA to use the connection and interact with MySQL You needs a Stateless session bean to use the JPA.
20
Summary You needs to declare an interface to expose functionality to external clients. You needs a JNDI lookup client which can run independently You needs a DI client in connection with EJB (Two components are package in EAR project), to be deployed in Glassfish and invoke them by Appclient.
21
Some suggestions Try to understand how different components interact with each other at implementation level. Do a thorough unit testing before integrating all components together Today’s lesson covers most but not all steps needed for lab 2. Feel free to change some steps if you think it is necessary.
22
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.