1 / 22

TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

TDDD05 EJB Lab (Part of slides reused from Mikhail’s). Lu Li lu.li@liu.se. Agenda. EJB brief introduction Practical hints. Why EJB. EJBs is a powerful component model for building distributed, server-side, and Java-based enterprise application components.

aliza
Download Presentation

TDDD05 EJB Lab (Part of slides reused from Mikhail’s)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  5. EJB architecture

  6. 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. DI Application • Deployment (Glassfish_Home)/bin/asadmin deploy –retrieve . Ex1-ee.ear • Execution (Glassfish_Home)/bin/Appclient –client ./ex1-eeClient.jar –mainclassclient.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?

More Related