tddd05 ejb lab part of slides reused from mikhail s
play

TDDD05 EJB Lab (Part of slides reused from Mikhails) Lu - PowerPoint PPT Presentation

TDDD05 EJB Lab (Part of slides reused from Mikhails) Lu Li lu.li@liu.se Agenda EJB brief introducDon PracDcal hints Why EJB EJBs is a


  1. TDDD05 ¡EJB ¡Lab ¡ (Part ¡of ¡slides ¡reused ¡from ¡Mikhail’s) ¡ Lu ¡Li ¡ lu.li@liu.se ¡

  2. Agenda ¡ • EJB ¡brief ¡introducDon ¡ • PracDcal ¡hints ¡

  3. Why ¡EJB ¡ • EJBs ¡is ¡a ¡powerful ¡component ¡model ¡for ¡ building ¡distributed, ¡server-­‑side, ¡and ¡Java-­‑ based ¡enterprise ¡applicaDon ¡components. ¡ • Code ¡reuse ¡by ¡middleware ¡service, ¡such ¡as ¡ object ¡life-­‑cycle ¡management, ¡resource ¡ (beans, ¡database ¡connecDon) ¡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 ¡connecDon ¡pool ¡(For ¡example ¡ “TDDD05_MySQL”), ¡and ¡do ¡a ¡ping ¡test ¡ • Configure ¡JDBC ¡resource ¡(For ¡example ¡ “TDDD05_JDBC”) ¡to ¡use ¡the ¡connecDon ¡pool ¡ (“TDDD05_MySQL”) ¡

  8. Create ¡an ¡JPA ¡to ¡use ¡database ¡ • JPA ¡is ¡a ¡kind ¡of ¡EJB ¡for ¡interacDon ¡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 ¡implementaDon ¡ ¡

  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 ¡ApplicaDon ¡

  15. Dependency ¡injecDon ¡

  16. DI ¡ApplicaDon ¡

  17. DI ¡ApplicaDon ¡ • Deployment ¡ ¡(Glassfish_Home)/bin/asadmin ¡deploy ¡– retrieve ¡. ¡Ex1-­‑ee.ear ¡ • ExecuDon ¡ ¡(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 ¡ connecDon ¡to ¡your ¡MySQL ¡ • You ¡needs ¡a ¡JPA ¡to ¡use ¡the ¡connecDon ¡and ¡ interact ¡with ¡MySQL ¡ • You ¡needs ¡a ¡Stateless ¡session ¡bean ¡to ¡use ¡the ¡ JPA. ¡ ¡

  20. Summary ¡ • You ¡needs ¡to ¡declare ¡an ¡interface ¡to ¡expose ¡ funcDonality ¡to ¡external ¡clients. ¡ • You ¡needs ¡a ¡JNDI ¡lookup ¡client ¡which ¡can ¡run ¡ independently ¡ • You ¡needs ¡a ¡DI ¡client ¡in ¡connecDon ¡with ¡EJB ¡ (Two ¡components ¡are ¡package ¡in ¡EAR ¡project), ¡ to ¡be ¡deployed ¡in ¡Glassfish ¡and ¡invoke ¡them ¡ by ¡Appclient. ¡

  21. Some ¡suggesDons ¡ • Try ¡to ¡understand ¡how ¡different ¡components ¡ interact ¡with ¡each ¡other ¡at ¡implementaDon ¡ level. ¡ • Do ¡a ¡thorough ¡unit ¡tesDng ¡before ¡integraDng ¡ 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. QuesDons? ¡ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend