• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Java EE6 CDI
 

Java EE6 CDI

on

  • 18,648 views

Presentation on Java EE 6 CDI with a twist of bashing Spring. Held at Callista Developers Conference 2010.

Presentation on Java EE 6 CDI with a twist of bashing Spring. Held at Callista Developers Conference 2010.

Statistics

Views

Total Views
18,648
Views on SlideShare
18,404
Embed Views
244

Actions

Likes
16
Downloads
0
Comments
4

16 Embeds 244

http://www.oschina.net 66
http://bnagur.blogspot.com 62
http://www.slideshare.net 54
http://bpbhat77.0fees.net 26
http://wap.oschina.net 9
http://www.linkedin.com 6
http://www.schoox.com 4
http://www.bpbhat77.0fees.net 4
http://192.168.6.52 4
https://twimg0-a.akamaihd.net 3
http://bnagur.blogspot.be 1
http://bnagur.blogspot.com.br 1
http://static.slidesharecdn.com 1
http://m.oschina.net 1
http://fmiredin.blogspot.com 1
https://www.linkedin.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

14 of 4 previous next Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Very useful info
    Are you sure you want to
    Your message goes here
    Processing…
  • I'll give you all your points regarding facts on Spring. The general point I want to make, is that it isn't as obvious as it has been, that Spring simplifies development over Java EE, when speaking for the average in-house application developer. I fully agree that Spring has far more complete architectural foundation, in terms of bootstrapping etc.
    Are you sure you want to
    Your message goes here
    Processing…
  • Valuable information on CDI but it would have made a better impression without the obviously wrong info in the first 3rd of the slidedeck:

    Slide 2: Besides the fact that the timelines are plain wrong (all the libraries that according to your graphics have been introduced in 2010 we're there from the beginning and there hasn't been any new modules in 2010 as Spring 3 came out in 2009), it's obvious that you took a list of modules available from the Subversion repository and blame it for being what? Comprehensive? So the time fact is wrong, you include modules purely needed for build, you include a lot of modules that approach APIs or problems JavaEE never cared about just to create the impression of Spring being bloated?

    Slide 3/4: Just note that there is a BeanDefinition abstraction inside Spring that completely decouples the factory's internals from the way it is configured. That's there since the early days. Spring *is* designed to use other config formats than XML (e.g. annotations, programatic or even properties files if you need). I think it is best practice to verify such bold statements if you like to place 'em that prominently ;).

    Regarding the need for best practices. There are developers out there that need choice, that don't want to turn off their brains because a technology implies there is one right way to achieve something. So IMHO choice is something valuable, as it raises the chance the technology as applicable to my problem space.

    Slide 5: So simply consider the Java EE toolsuite to be Netbeans provided by Sun. Where's the difference?

    So I thinks it's a pity to wash-out the great CDI overview with such a daring intro that everyone who has a little insight into Spring will recognize to be wrong anyway.

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

Java EE6 CDI Java EE6 CDI Presentation Transcript

  • 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