SlideShare uma empresa Scribd logo
1 de 18
The	
  New	
  Java	
  EE
            CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model
            for	
  Java	
  EE	
  6.	
  BeAer	
  than	
  Spring?

            Johan	
  Eltes	
  |	
  johan.eltes@callistaenterprise.se	
  |	
  Cadec	
  2010-­‐01-­‐20




onsdag 27 januari 2010                                                                                 1
Once	
  upon	
  a	
  time	
  Spring	
  was	
  comprehensible…

                                                                                                                                                 1   0
                                                                                                                                              20




                                                                                                         0   8
                                                                                                      20


                                                0    4
                                             20




       2         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6              ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                   2
Are	
  you	
  a	
  Java	
  or	
  XML	
  developer?




       3         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6   ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                        3
Spring	
  wasn’t	
  built	
  bottom	
  up	
  for	
  noxml



      Spring	
  wasn’t	
  built	
  bo?om	
  up	
  for	
  noXML




                                You	
  need	
  to	
  understand	
  what	
  can	
  be	
  done	
  using	
  JavaConfig	
  /	
  annotaFons	
  and	
  when	
  to	
  step	
  
                                down	
  to	
  XML.




                                                                       There	
  are	
  so	
  many	
  options	
  in	
  Spring	
  that	
  you	
  need	
  a	
  100	
  page	
  company-­best-­practice	
  guide	
  so	
  that	
  
                                                                       developers	
  can	
  read	
  each	
  others	
  code.




       4         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                                                            ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                                                 4
Complex	
  tools	
  require	
  tool	
  suites




       5         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6   ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                        5
Meanwhile,	
  Java	
  EE	
  is	
  shrinking...



                                                                                                                                    o Rile
                                                                                                                              	
  Pr
                                                                                                                           eb
                                                                                                                	
  6 	
  W
                                                                                                         a	
  EE
                                                                                                      Jav


                                                       E
                                                va	
  E
                                       l l	
  Ja
                                  Fu




       6         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                                          ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                               6
...and	
  moving	
  to	
  a	
  very	
  slick	
  DI-­based	
  component	
  
           model:	
  CDI


                                                                                                                                                               CDI	
  requires	
  support	
  
                                                                                                                                                               from	
  an	
  EJB	
  3.1	
  Light-­‐
                                                                                                                                                               container	
  for	
  EJB-­‐
                                                                          CDI	
  container	
  (injecKon,	
  aop,	
  contexts)                                  specific	
  capabiliKes	
  
                                                                                                                                                               (transatcions,	
  
                                                                                                                                                               security)
               JSF/Facelets

                                                                                                  Managed	
  Bean
                                                                                         Special	
  case:	
  EJB	
  Session	
  and	
  Singleton                                                       CDI	
  container	
  
                                                                                                                                                                   CDI	
  container	
                 will	
  offer	
  the	
  
                                                                                                                                                                   will	
  resolve	
                  bean	
  for	
  
                                                                                                                                                                   dependency                         injecKon	
  


                                                   Servlets
                                                                                                      MDBs                                 WS


                          CDI	
  consolidates	
  JSR	
  250	
  (common	
  annota7ons),	
  JSR-­‐330	
  ( javax.inject)	
  and	
  “EJB	
  3.1	
  
                          light”	
  into	
  a	
  unified	
  “POJO”	
  component	
  model.




       7         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                                               ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                                          7
So,	
  let’s	
  have	
  a	
  look	
  at	
  CDI!

                                                                                                      All demo code for the use-cases are available for public checkout at this
                                                                                                      svn repo:

           • Use-­‐cases	
  for	
  CDI                                                                https://svn.callistaenterprise.se/public/Cadec/Cadec2010/cdi/trunk

               – UC	
  1:	
  Basic	
  DI	
  for	
  Unit	
  tesKng
               – UC	
  2:	
  Factories	
  and	
  qualifiers
               – UC	
  3:	
  IntegraKon	
  tesKng	
  in	
  JUnit
               – UC	
  4:	
  AOP	
  with	
  interceptors
               – UC	
  5:	
  Loose	
  coupling	
  with	
  events
               – UC	
  6:	
  Handling	
  of	
  scopes
               – UC	
  7:	
  Extensions




                AnnotaKons,	
  annotaKons,	
  annotaKons...	
  @Inject,	
  @Produces,	
  @Qualifer,	
  @AlternaKve,	
  @Stateless,	
  @ConversaKon




       8         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                                     ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                          8
UC	
  1:	
  Basic	
  DI	
  for	
  Unit	
  testing



                                                                                  Interface:	
  OrderDao   Class
                                                                                                           OracleOrderDaoImpl extends
                      Class	
  OrderServiceImpl	
  {                                                       OrderDao
                         @Inject
                         OrderDao	
  orderDao;
                         ...                                                         ?
                     }

                                                                                                           Class
                                                                                                           MySqlOrderDaoImpl extends
                                                                                                           OrderDao




                                                                                                           Class
                                                                                                           MockOrderDaoImpl extends
                                                                                                           OrderDao




                         @Inject	
  is	
  by	
  default	
  auto-­‐injecKon	
  by	
  type




       9         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                     ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                          9
9

                    UC	
  2:	
  Factories	
  and	
  qualiRiers

                                                                                                                     Instance of
                                                                                                                     Class JmsTemplate:                    @DestClass(ERROR)	
  
                                                                                                    Interface:	
        receiveTimeout: 3000
                                                                                                                        defaultDestinationName: “error.queue”
                                                                                                   JmsTemplate          ...

                                                                                                                     Instance of
                                                                                                                     Class JmsTemplate:                   @	
  DestClass(LOG)	
  
                 Class	
  OrderServiceImpl	
  {                                                                         receiveTimeout: 100
                    @Inject                                                                                             defaultDestinationName: “log.queue”
                    JmsTemplate	
  @JTQualifer(ERROR)                                                                   ...
                    errorDestTemplate;                                                         ?
                    ...                                                                                              Instance of
                }                                                                                                    Class JmsTemplate:                    @Named(“service1”)
                                                                                                                        receiveTimeout: 4000
                                                                                                                        defaultDestinationName: “service1”
                                                                                                                        ...



                          Class
                         JmsTemplateFactory	
  	
  {
                             @Producer	
  @DestClass(ERROR)	
  JmsTemplate	
  getErrorDestTemplate()	
  {}
                             @Producer	
  @DestClass(LOG)	
  JmsTemplate	
  getLogDestTemplate()	
  {}	
  
                             @Producer	
  @Named(“invoice”)	
  JmsTemplate	
  getInvoiceDestTemplate()	
  {}
                         }




                                       With	
  @Produces	
  we	
  can	
  create	
  mulKple	
  beans	
  of	
  the	
  same	
  type
                                       With	
  @Qualifier-­‐annotaKons,	
  we	
  select	
  which	
  bean	
  to	
  inject



          10         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                         ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
    onsdag 27 januari 2010                                                                                                                                                                              10
UC	
  3:	
  Integration	
  testing	
  with	
  JUnit



                                                                                                          How	
  much	
  weight	
  has	
  EJB	
  lost??

                                                                                                                           	
  Demo:
                                                                                                      JUnit	
  TestCase-­‐>TestEjb-­‐>Ejb-­‐>Dao-­‐>JPA

                                                                                                         ...with	
  embeddable	
  EJB	
  container




      11         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6               ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                    11
9


            UC	
  4:	
  Cross-­cutting	
  concerns


           Class	
  OrderServiceImpl	
  {
                                                                                       Interface:	
  OrderDao
              @Inject                                                                                                                  @Trace
              OrderDao	
  orderDao;                                                                                                    Class OracleOrderDaoImpl extends OrderDao
              ...                                                                                                                      {
          }                                                                                                                               Order save(Order order) {
                                                                                                                                          }
                                                                                                                                       }


                                                                                @Trace @Interceptor
                                                                               public class TraceLogInterceptor {
                                                                                       @AroundInvoke
                                                                                       public Object trace(InvocationContext
                                                                               ctx)
                                                                                          throws Exception { ... }
                                                                               }




                      Sample:	
  Trace	
  entry	
  and	
  exit	
  of	
  method	
  invocaKons	
  in	
  all	
  classes	
  annotated	
  with	
  @Trace




          12           CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                            ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
    onsdag 27 januari 2010                                                                                                                                                                                   12
UC	
  5:	
  Events

      Class CustomerFormBean {
         @Inject                                                                                      Class CustomerServiceImpl {
         CustomerService cs;                                                                             @Inject @Deleted
                                                                                                         Event<Customer>
          public void delete(Customer                                                                    deletedEvent;
          c) {
               cs.delete(c)                                                                             public void delete(Customer c)
          }                                                                                             {
     }                                                                                                     ...                                                  “CDI Event broker”
                                                                                                           deletedEvent.fire(c);
                                                                                                        }




                            Class	
  OrderServiceImpl	
  {
                           }
                               @Inject	
  OrderDao	
  od;

                                 public	
  void	
  validateDelete(@Observes	
  @Deleted	
  Customer	
  c)	
  {
                                    if	
  (od.hasOrderForCustomer(c))	
  throw	
  new	
  VetoExcepKon();
                                 }
                           }




                           Order	
  service	
  listens	
  to	
  customer	
  deleKon	
  events	
  to	
  prevent	
  deleKon	
  of	
  customers	
  with	
  orders.




         13      CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                                      ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                           13
UC	
  6:	
  Declarative	
  scope	
  management


              • ejb	
  Session                                                                        CDI handles the scoping /
                                                                                                      context aspects of EJBs as
              • ejb	
  Singleton                                                                      well (without an EJB
                                                                                                      container)

              • ApplicaKonScoped
              • RequestScoped
              • SessionScoped
              • ConversaKonScoped


              • AddiKonal	
  scopes	
  	
  may	
  be	
  added	
  via	
  extenKon	
  api	
  (“SPI”)




                            Use-­‐case	
  5:	
  	
  Contextual	
  services




      14         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                            ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                                 14
9

                    UC	
  7:	
  Extentions	
  -­	
  Sample:	
  conRig	
  Rile

                                                                                                                     Instance of
                                                                                                                     Class JmsTemplate:                    @DestClass(ERROR)	
  
                                                                                                    Interface:	
        receiveTimeout: 3000
                                                                                                                        defaultDestinationName: “error.queue”
                                                                                                   JmsTemplate          ...

                                                                                                                     Instance of
                                                                                                                     Class JmsTemplate:                   @	
  DestClass(LOG)	
  
                 Class	
  OrderServiceImpl	
  {                                                                         receiveTimeout: 100
                    @Inject                                                                                             defaultDestinationName: “log.queue”
                    JmsTemplate	
  @JTQualifer(ERROR)                                                                   ...
                    errorDestTemplate;                                                         ?
                    ...                                                                                              Instance of
                }                                                                                                    Class JmsTemplate:                     @Named(“invoice”)
                                                                                                                        receiveTimeout: 4000
                                                                                                                        defaultDestinationName: “invoice.queue”
                                                                                                                        ...



                          Class
                         JmsTemplateFactory	
  	
  {
                             @Producer	
  @DestClass(ERROR)	
  JmsTemplate	
  getErrorDestTemplate()	
  {}
                             @Producer	
  @DestClass(LOG)	
  JmsTemplate	
  getLogDestTemplate()	
  {}	
  
                             @Producer	
  @Named(“invoice”)	
  JmsTemplate	
  getInvoiceDestTemplate()	
  {}
                         }




                                           Sample:	
  Extension	
  for	
  file-­‐based	
  configuraKon	
  of	
  @Producers



          15         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                         ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
    onsdag 27 januari 2010                                                                                                                                                                              15
Is	
  Java	
  EE	
  6	
  and	
  CDI	
  for	
  me?

        • Why?
              – Java	
  EE	
  development	
  is	
  FUN	
  (producKve)	
  again!
              – It	
  is	
  a	
  neat,	
  simple	
  model
              – Zero	
  config	
  /	
  overhead	
  /	
  layers	
  if	
  you	
  want	
  to	
  start	
  simple
              – Do	
  we	
  sKll	
  need	
  “help”	
  from	
  Spring?
        • When?
              – JBoss,	
  Oracle	
  and	
  Sun	
  seems	
  to	
  be	
  there	
  “soon”
              – Likely	
  to	
  get	
  OS-­‐extensions	
  that	
  bring	
  it	
  to	
  Tomcat	
  very	
  soon
        • Who?
              – Very	
  good	
  news	
  for	
  no-­‐floss-­‐shops	
  :)
              – OpKon	
  for	
  building	
  up	
  Spring	
  competence	
  -­‐	
  Java	
  EE	
  6	
  Web	
  Profile	
  is	
  likely	
  an	
  easier	
  start




      16         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6                 ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                                      16
Thank’s	
  for	
  listening!




      17         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6   ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                        17
Credits


        • Image	
  of	
  feathers:
              – hAp://askabiologist.asu.edu




      18         CDI	
  -­‐	
  the	
  re-­‐invented	
  component	
  model	
  for	
  Java	
  EE	
  6   ©	
  2010	
  Callista	
  Enterprise	
  |	
  www.callistaenterprise.se
onsdag 27 januari 2010                                                                                                                                                        18

Mais conteúdo relacionado

Destaque

Destaque (11)

Kontaktmøte 15. februar 2007
Kontaktmøte 15. februar 2007Kontaktmøte 15. februar 2007
Kontaktmøte 15. februar 2007
 
Self-stigma: an unspoken world of unspoken things - Nadine Ferris France
Self-stigma: an unspoken world of unspoken things - Nadine Ferris FranceSelf-stigma: an unspoken world of unspoken things - Nadine Ferris France
Self-stigma: an unspoken world of unspoken things - Nadine Ferris France
 
Voltem pel món 2015 - Ens presentem
Voltem pel món 2015 - Ens presentemVoltem pel món 2015 - Ens presentem
Voltem pel món 2015 - Ens presentem
 
Words That Work II: The Phrases That Encourage Planned Giving
Words That Work II: The Phrases That Encourage Planned Giving Words That Work II: The Phrases That Encourage Planned Giving
Words That Work II: The Phrases That Encourage Planned Giving
 
Крым
КрымКрым
Крым
 
Cтены AEROC по антикризисным ценам рациональное применение стройматериалов
Cтены AEROC по антикризисным ценам рациональное применение стройматериаловCтены AEROC по антикризисным ценам рациональное применение стройматериалов
Cтены AEROC по антикризисным ценам рациональное применение стройматериалов
 
Cahaya
CahayaCahaya
Cahaya
 
الدرس العملي الرابع
الدرس العملي الرابعالدرس العملي الرابع
الدرس العملي الرابع
 
Molts anys i bons fidel!!!
Molts anys i bons fidel!!!Molts anys i bons fidel!!!
Molts anys i bons fidel!!!
 
Visita aisha
Visita aishaVisita aisha
Visita aisha
 
Visita primer
Visita primerVisita primer
Visita primer
 

Semelhante a Java EE6 CDI

Jee Overview Ppt
Jee Overview PptJee Overview Ppt
Jee Overview Ppt
pmanvi
 
Introduction to spring
Introduction to springIntroduction to spring
Introduction to spring
odedns
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
Hirofumi Iwasaki
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
mfrancis
 
Comparing javawebframeworks apacheconus2007
Comparing javawebframeworks apacheconus2007Comparing javawebframeworks apacheconus2007
Comparing javawebframeworks apacheconus2007
Geococcyx
 

Semelhante a Java EE6 CDI (20)

Java EE 6 and GlassFish portfolio
Java EE 6 and GlassFish portfolioJava EE 6 and GlassFish portfolio
Java EE 6 and GlassFish portfolio
 
Jee Overview Ppt
Jee Overview PptJee Overview Ppt
Jee Overview Ppt
 
Jee Overview Ppt
Jee Overview PptJee Overview Ppt
Jee Overview Ppt
 
Introduction to spring
Introduction to springIntroduction to spring
Introduction to spring
 
OSGi Community Event 2010 - A Crash Course in OSGi Application Development
OSGi Community Event 2010 - A Crash Course in OSGi Application DevelopmentOSGi Community Event 2010 - A Crash Course in OSGi Application Development
OSGi Community Event 2010 - A Crash Course in OSGi Application Development
 
JMS 2.0
JMS 2.0JMS 2.0
JMS 2.0
 
Smalltalk in Enterprise Applications
Smalltalk in Enterprise ApplicationsSmalltalk in Enterprise Applications
Smalltalk in Enterprise Applications
 
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and WicketComparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
 
How to Thrive on REST/WebSocket-Based Microservices
How to Thrive on REST/WebSocket-Based MicroservicesHow to Thrive on REST/WebSocket-Based Microservices
How to Thrive on REST/WebSocket-Based Microservices
 
Elaster Labs, the 1st PaaS in Taiwan
Elaster Labs, the 1st PaaS in TaiwanElaster Labs, the 1st PaaS in Taiwan
Elaster Labs, the 1st PaaS in Taiwan
 
EJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and StrategyEJB and CDI - Alignment and Strategy
EJB and CDI - Alignment and Strategy
 
JEE 8, A Big Overview
JEE 8, A Big OverviewJEE 8, A Big Overview
JEE 8, A Big Overview
 
Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7Seven Points for Applying Java EE 7
Seven Points for Applying Java EE 7
 
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph!  ...
Bytecode Weaving in OSGi – Enhance Your Classes, Not Your Dependency graph! ...
 
What's new in Java EE 6
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6
 
Next-Generation Enterprise Application Development with SpringSource dm Serve...
Next-Generation Enterprise Application Development with SpringSource dm Serve...Next-Generation Enterprise Application Development with SpringSource dm Serve...
Next-Generation Enterprise Application Development with SpringSource dm Serve...
 
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
 
Comparing javawebframeworks apacheconus2007
Comparing javawebframeworks apacheconus2007Comparing javawebframeworks apacheconus2007
Comparing javawebframeworks apacheconus2007
 
Excel 2010 Power Pivot Seminar
Excel 2010   Power Pivot SeminarExcel 2010   Power Pivot Seminar
Excel 2010 Power Pivot Seminar
 
GlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUGGlassFish & Java EE Business Update @ CEJUG
GlassFish & Java EE Business Update @ CEJUG
 

Mais de Johan Eltes

2013 mobile health summit
2013 mobile health summit2013 mobile health summit
2013 mobile health summit
Johan Eltes
 
2013 10-16 sundsvall42 journaluppgifter i appar
2013 10-16 sundsvall42 journaluppgifter i appar2013 10-16 sundsvall42 journaluppgifter i appar
2013 10-16 sundsvall42 journaluppgifter i appar
Johan Eltes
 

Mais de Johan Eltes (20)

2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicin2018 04-25 vitalis refark telemedicin
2018 04-25 vitalis refark telemedicin
 
Sweden on fhir - status report
Sweden on fhir - status reportSweden on fhir - status report
Sweden on fhir - status report
 
The ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payersThe ehealth architecture of the Swedish public healthcare payers
The ehealth architecture of the Swedish public healthcare payers
 
Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...Presentation of a pre-study on a national ecosystem for a shared medication r...
Presentation of a pre-study on a national ecosystem for a shared medication r...
 
Nordic reference architecture personal connected health
Nordic reference architecture personal connected healthNordic reference architecture personal connected health
Nordic reference architecture personal connected health
 
Swedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-XSwedish Health Innovation Resources at Stanford Med-X
Swedish Health Innovation Resources at Stanford Med-X
 
2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjning2014 04-08 arkitektur för gemensam informationsförsörjning
2014 04-08 arkitektur för gemensam informationsförsörjning
 
10 år av standarder med standarder i nationell ohälsa
10 år av standarder med standarder i nationell ohälsa10 år av standarder med standarder i nationell ohälsa
10 år av standarder med standarder i nationell ohälsa
 
2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected health2016 04-06 vitalis nordic reference architecture personal connected health
2016 04-06 vitalis nordic reference architecture personal connected health
 
How Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealthHow Sweden improved patient self service with ehealth
How Sweden improved patient self service with ehealth
 
2013 mobile health summit
2013 mobile health summit2013 mobile health summit
2013 mobile health summit
 
2013 10-16 sundsvall42 journaluppgifter i appar
2013 10-16 sundsvall42 journaluppgifter i appar2013 10-16 sundsvall42 journaluppgifter i appar
2013 10-16 sundsvall42 journaluppgifter i appar
 
OAuth2 in swedish healthcare
OAuth2 in swedish healthcareOAuth2 in swedish healthcare
OAuth2 in swedish healthcare
 
Invånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdataInvånar styrd åtkomst av patientdata
Invånar styrd åtkomst av patientdata
 
DCI with groovy
DCI with groovyDCI with groovy
DCI with groovy
 
Sca
ScaSca
Sca
 
The Web Framework Dream Team
The Web Framework Dream TeamThe Web Framework Dream Team
The Web Framework Dream Team
 
Asynch Soa
Asynch SoaAsynch Soa
Asynch Soa
 
Reference Architecture
Reference ArchitectureReference Architecture
Reference Architecture
 
Mashups
MashupsMashups
Mashups
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Java EE6 CDI

  • 1. The  New  Java  EE CDI  -­‐  the  re-­‐invented  component  model for  Java  EE  6.  BeAer  than  Spring? Johan  Eltes  |  johan.eltes@callistaenterprise.se  |  Cadec  2010-­‐01-­‐20 onsdag 27 januari 2010 1
  • 2. Once  upon  a  time  Spring  was  comprehensible… 1 0 20 0 8 20 0 4 20 2 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 2
  • 3. Are  you  a  Java  or  XML  developer? 3 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 3
  • 4. Spring  wasn’t  built  bottom  up  for  noxml Spring  wasn’t  built  bo?om  up  for  noXML You  need  to  understand  what  can  be  done  using  JavaConfig  /  annotaFons  and  when  to  step   down  to  XML. There  are  so  many  options  in  Spring  that  you  need  a  100  page  company-­best-­practice  guide  so  that   developers  can  read  each  others  code. 4 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 4
  • 5. Complex  tools  require  tool  suites 5 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 5
  • 6. Meanwhile,  Java  EE  is  shrinking... o Rile  Pr eb  6  W a  EE Jav E va  E l l  Ja Fu 6 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 6
  • 7. ...and  moving  to  a  very  slick  DI-­based  component   model:  CDI CDI  requires  support   from  an  EJB  3.1  Light-­‐ container  for  EJB-­‐ CDI  container  (injecKon,  aop,  contexts) specific  capabiliKes   (transatcions,   security) JSF/Facelets Managed  Bean Special  case:  EJB  Session  and  Singleton CDI  container   CDI  container   will  offer  the   will  resolve   bean  for   dependency injecKon   Servlets MDBs WS CDI  consolidates  JSR  250  (common  annota7ons),  JSR-­‐330  ( javax.inject)  and  “EJB  3.1   light”  into  a  unified  “POJO”  component  model. 7 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 7
  • 8. So,  let’s  have  a  look  at  CDI! All demo code for the use-cases are available for public checkout at this svn repo: • Use-­‐cases  for  CDI https://svn.callistaenterprise.se/public/Cadec/Cadec2010/cdi/trunk – UC  1:  Basic  DI  for  Unit  tesKng – UC  2:  Factories  and  qualifiers – UC  3:  IntegraKon  tesKng  in  JUnit – UC  4:  AOP  with  interceptors – UC  5:  Loose  coupling  with  events – UC  6:  Handling  of  scopes – UC  7:  Extensions AnnotaKons,  annotaKons,  annotaKons...  @Inject,  @Produces,  @Qualifer,  @AlternaKve,  @Stateless,  @ConversaKon 8 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 8
  • 9. UC  1:  Basic  DI  for  Unit  testing Interface:  OrderDao Class OracleOrderDaoImpl extends Class  OrderServiceImpl  { OrderDao @Inject OrderDao  orderDao; ... ? } Class MySqlOrderDaoImpl extends OrderDao Class MockOrderDaoImpl extends OrderDao @Inject  is  by  default  auto-­‐injecKon  by  type 9 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 9
  • 10. 9 UC  2:  Factories  and  qualiRiers Instance of Class JmsTemplate: @DestClass(ERROR)   Interface:   receiveTimeout: 3000 defaultDestinationName: “error.queue” JmsTemplate ... Instance of Class JmsTemplate: @  DestClass(LOG)   Class  OrderServiceImpl  { receiveTimeout: 100 @Inject defaultDestinationName: “log.queue” JmsTemplate  @JTQualifer(ERROR) ... errorDestTemplate; ? ... Instance of } Class JmsTemplate: @Named(“service1”) receiveTimeout: 4000 defaultDestinationName: “service1” ... Class JmsTemplateFactory    { @Producer  @DestClass(ERROR)  JmsTemplate  getErrorDestTemplate()  {} @Producer  @DestClass(LOG)  JmsTemplate  getLogDestTemplate()  {}   @Producer  @Named(“invoice”)  JmsTemplate  getInvoiceDestTemplate()  {} } With  @Produces  we  can  create  mulKple  beans  of  the  same  type With  @Qualifier-­‐annotaKons,  we  select  which  bean  to  inject 10 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 10
  • 11. UC  3:  Integration  testing  with  JUnit How  much  weight  has  EJB  lost??  Demo: JUnit  TestCase-­‐>TestEjb-­‐>Ejb-­‐>Dao-­‐>JPA ...with  embeddable  EJB  container 11 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 11
  • 12. 9 UC  4:  Cross-­cutting  concerns Class  OrderServiceImpl  { Interface:  OrderDao @Inject @Trace OrderDao  orderDao; Class OracleOrderDaoImpl extends OrderDao ... { } Order save(Order order) { } } @Trace @Interceptor public class TraceLogInterceptor { @AroundInvoke public Object trace(InvocationContext ctx) throws Exception { ... } } Sample:  Trace  entry  and  exit  of  method  invocaKons  in  all  classes  annotated  with  @Trace 12 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 12
  • 13. UC  5:  Events Class CustomerFormBean { @Inject Class CustomerServiceImpl { CustomerService cs; @Inject @Deleted Event<Customer> public void delete(Customer deletedEvent; c) { cs.delete(c) public void delete(Customer c) } { } ... “CDI Event broker” deletedEvent.fire(c); } Class  OrderServiceImpl  { } @Inject  OrderDao  od; public  void  validateDelete(@Observes  @Deleted  Customer  c)  { if  (od.hasOrderForCustomer(c))  throw  new  VetoExcepKon(); } } Order  service  listens  to  customer  deleKon  events  to  prevent  deleKon  of  customers  with  orders. 13 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 13
  • 14. UC  6:  Declarative  scope  management • ejb  Session CDI handles the scoping / context aspects of EJBs as • ejb  Singleton well (without an EJB container) • ApplicaKonScoped • RequestScoped • SessionScoped • ConversaKonScoped • AddiKonal  scopes    may  be  added  via  extenKon  api  (“SPI”) Use-­‐case  5:    Contextual  services 14 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 14
  • 15. 9 UC  7:  Extentions  -­  Sample:  conRig  Rile Instance of Class JmsTemplate: @DestClass(ERROR)   Interface:   receiveTimeout: 3000 defaultDestinationName: “error.queue” JmsTemplate ... Instance of Class JmsTemplate: @  DestClass(LOG)   Class  OrderServiceImpl  { receiveTimeout: 100 @Inject defaultDestinationName: “log.queue” JmsTemplate  @JTQualifer(ERROR) ... errorDestTemplate; ? ... Instance of } Class JmsTemplate: @Named(“invoice”) receiveTimeout: 4000 defaultDestinationName: “invoice.queue” ... Class JmsTemplateFactory    { @Producer  @DestClass(ERROR)  JmsTemplate  getErrorDestTemplate()  {} @Producer  @DestClass(LOG)  JmsTemplate  getLogDestTemplate()  {}   @Producer  @Named(“invoice”)  JmsTemplate  getInvoiceDestTemplate()  {} } Sample:  Extension  for  file-­‐based  configuraKon  of  @Producers 15 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 15
  • 16. Is  Java  EE  6  and  CDI  for  me? • Why? – Java  EE  development  is  FUN  (producKve)  again! – It  is  a  neat,  simple  model – Zero  config  /  overhead  /  layers  if  you  want  to  start  simple – Do  we  sKll  need  “help”  from  Spring? • When? – JBoss,  Oracle  and  Sun  seems  to  be  there  “soon” – Likely  to  get  OS-­‐extensions  that  bring  it  to  Tomcat  very  soon • Who? – Very  good  news  for  no-­‐floss-­‐shops  :) – OpKon  for  building  up  Spring  competence  -­‐  Java  EE  6  Web  Profile  is  likely  an  easier  start 16 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 16
  • 17. Thank’s  for  listening! 17 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 17
  • 18. Credits • Image  of  feathers: – hAp://askabiologist.asu.edu 18 CDI  -­‐  the  re-­‐invented  component  model  for  Java  EE  6 ©  2010  Callista  Enterprise  |  www.callistaenterprise.se onsdag 27 januari 2010 18

Notas do Editor

  1. S&amp;#xE4;g att ultimata beviset f&amp;#xF6;r att en &amp;#x201C;l&amp;#xE4;ttviktig&amp;#x201D; milj&amp;#xF6; gubbat till sig, &amp;#xE4;r att det beh&amp;#xF6;vs en specialpaketerad eclipse-distribution.
  2. Spring &amp;#xE4;r definitivt d&amp;#xE4;r. Det &amp;#xE4;r en stor plattform i sig sj&amp;#xE4;lv. Vi beh&amp;#xF6;ver n&amp;#xE5;got l&amp;#xE4;ttviktigare!
  3. Ta av ryggs&amp;#xE4;cken!
  4. N&amp;#xE4;mn tydligt att det handlar om annoteringsbaserad komponentmodel! Det finns inget standardiserat s&amp;#xE4;tt konfigurera &amp;#x201C;b&amp;#xF6;nor&amp;#x201D; med XML i CDI.
  5. Det &amp;#xE4;r ju trots allt enhetsestning / TDD som &amp;#xE4;r drivkraften f&amp;#xF6;r DI! G&amp;#xE5; l&amp;#xE5;ngsamt igenom projektet. Visa beans.xml. Dema usecase 1 - brytpunkt i Service, visa att DAO injecerats.
  6. Qualifiers: - F&amp;#xF6;rklara - &amp;#xD6;ppna Qualifer-annoteringen Producers - Klarg&amp;#xF6;r att detta blir extra mycket anv&amp;#xE4;nt n&amp;#xE4;r man inte har XML-konfigurering. En klass kan ju bara ha en annotering, men m&amp;#xE5;nga bean-konfigar (i Spring) - Visa JmsTemplates och f&amp;#xF6;rklara f&amp;#xF6;rst producer methods och sedan producer fields.
  7. Ta p&amp;#xE5; den lilla ryggs&amp;#xE4;cken! Kommentera Spring integrationstestning! G&amp;#xE5; igenom upps&amp;#xE4;ttningen. med Test-EJB. - Visa testcase. - Visa Resources-klassen (producer som arv i Java EE 5) - Visa Dao och s&amp;#xE4;tt brytpunkt d&amp;#xE4;r, visa att EntityManager har injecerats.
  8. Use-case 3: Systematically handle cross-cutting concerns (&quot;AOP&quot;) Rational: - Toggling technical features like transaction handling, logging, etc without editing a lot of classes Charactersistics - One bean per class (of technical feature) Options for annotation based DI - Integration of a full-fledged point-cut language (e.g. aspectj) - Injecting proxy handlers (interceptor) based on annotations - Injecting type-compatible &amp;#x201C;pre-preprocessor&amp;#x201D; (decorator) based on annotations Dema: - Visa koden - K&amp;#xF6;r koden och visa konsolen.
  9. Brokering of events between beans - Beskriv caset - Visa koden - kommentera att det &amp;#xE4;r typs&amp;#xE4;kert, l&amp;#xE4;tviktigt och flexibelt
  10. Use-case 5: Contextual services G&amp;#xE5; igenom bilden. Ingen demo.
  11. SPI f&amp;#xF6;r: - metaprogrammering - integrera CDI-implementationer i olika containers (t.ex. Weld i Tomcat) - Att g&amp;#xF6;ra kundspecifika till&amp;#xE4;gg till programmeringsmodellen Demo! - Visa TemplateProducern - K&amp;#xF6;r koden - &amp;#xC4;ndra i filen - Visa att testet fallerar