Java EE and Spring Framework Shootout - Reza Rahman

26 downloads 204 Views 3MB Size Report
Java EE 6 & Spring 3.0, 3.1 highlights. ▫ Spring 3.1 feature comparison with Java EE 6. ▫ CDI and ... Enables use of EJB 3.0 components as JSF managed beans.
Java EE and Spring Framework Shootout  Rohit Kelapure IBM Advisory Software Engineer, http://wasdynacache.blogspot.com/  Reza Rahman Independent Consultant, Author, Java EE Expert http://www.rahmannet.net/  Presentation can be downloaded from http://db.tt/1q9us2JH

© 2011 IBM Corporation

Important Disclaimers

 THE INFORMATION CONTAINED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY.  WHILST EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION CONTAINED IN THIS PRESENTATION, IT IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED.  ALL PERFORMANCE DATA INCLUDED IN THIS PRESENTATION HAVE BEEN GATHERED IN A CONTROLLED ENVIRONMENT. YOUR OWN TEST RESULTS MAY VARY BASED ON HARDWARE, SOFTWARE OR INFRASTRUCTURE DIFFERENCES.  ALL DATA INCLUDED IN THIS PRESENTATION ARE MEANT TO BE USED ONLY AS A GUIDE.  IN ADDITION, THE INFORMATION CONTAINED IN THIS PRESENTATION IS BASED ON IBM’S CURRENT PRODUCT PLANS AND STRATEGY, WHICH ARE SUBJECT TO CHANGE BY IBM, WITHOUT NOTICE.  IBM AND ITS AFFILIATED COMPANIES SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, THIS PRESENTATION OR ANY OTHER DOCUMENTATION.  NOTHING CONTAINED IN THIS PRESENTATION IS INTENDED TO, OR SHALL HAVE THE EFFECT OF:  - CREATING ANY WARRANT OR REPRESENTATION FROM IBM, ITS AFFILIATED COMPANIES OR ITS OR THEIR SUPPLIERS AND/OR LICENSORS

2

© 2011 IBM Corporation

Copyright and Trademarks

 © IBM Corporation 2011. All Rights Reserved.

 IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., and registered in many jurisdictions worldwide.

 Other product and service names might be trademarks of IBM or other companies.

 A current list of IBM trademarks is available on the Web – see the IBM “Copyright and trademark information” page at URL: www.ibm.com/legal/copytrade.shtml

3

© 2011 IBM Corporation

Outline

 Evolution of Java EE and Spring  Java EE 6 & Spring 3.0, 3.1 highlights  Spring 3.1 feature comparison with Java EE 6  CDI and Spring ecosystem  Spring and Java EE coexistence  Conclusion

4

© 2011 IBM Corporation

J2EE Java EE Specifications

* Introduced in spec. © 2011 IBM Corporation

Evolution of J2EE Java EE6 (Dec 09)

6

© 2011 IBM Corporation

JSR 299 Contexts and Dependency Injection (CDI)  Adds dependency injection to JEE and makes it type-safe.  Hollywood principle - Don’t call us, we will call you  No hard coded dependencies on other specifications  Assists in unifying the Bean model  Well defined contexts, the ability to bind beans statefully to them & manage their lifecycle.  Introduces an event notification system to decouple producers & consumers  Uses interceptors to foster loose coupling – Extend behavior with type safe interceptor bindings – Refines interceptors into decorators for finer grained control  Integrates with the Unified EL to bridge JSF – Enables use of EJB 3.0 components as JSF managed beans  Introduces an SPI to extend JEE – Roll your own JEE7! – Not only an API but also a SPI – Rich ecosystem of CDI extensions  Adds the Web conversation context  Spring does NOT provide support for CDI

7

© 2011 IBM Corporation

Evolution of Spring [ 1.0, 2.0, 2.5, 3.0, 3.1]

8

© 2011 IBM Corporation

Spring Framework

 Lightweight dependency injection  Aspect oriented  Layered application & container framework  Well defined modules on top of the core container  NOT an all-or-nothing solution 9

© 2011 IBM Corporation

Birds Eye View

10

© 2011 IBM Corporation

Java EE vs. Spring Framework Features/APIs Overview

11

© 2011 IBM Corporation

Java EE vs. Spring Business Component

12

© 2011 IBM Corporation

Spring XML for Business Component Injection

13

© 2011 IBM Corporation

Spring XML for Business Component Injection

14

© 2011 IBM Corporation

Spring Java Based Configuration

15

© 2011 IBM Corporation

Spring Java Based Configuration

16

© 2011 IBM Corporation

Java EE Interceptor vs. Spring Aspects

17

© 2011 IBM Corporation

Java EE vs. Spring Injection

18

© 2011 IBM Corporation

Java EE vs. Spring Injection – Spring configuration

19

© 2011 IBM Corporation

JSF 2 vs. Spring MVC Front Controller Facelet Component

20

© 2011 IBM Corporation

JSF 2 vs. Spring MVC Front Controller Facelet

21

© 2011 IBM Corporation

JSF 2 vs. Spring MVC Front Controller JSF Event Handler

22

Entity

© 2011 IBM Corporation

JSF 2 vs. Spring MVC Spring MVC JSP

23

© 2011 IBM Corporation

Spring MVC Configuration

24

© 2011 IBM Corporation

Spring Controller

25

© 2011 IBM Corporation

Spring MVC web.xml configuration

26

© 2011 IBM Corporation

Java EE vs. Spring Scheduling

27

© 2011 IBM Corporation

Java EE vs. Spring Scheduling

28

© 2011 IBM Corporation

Java EE vs. Spring Messaging

29

© 2011 IBM Corporation

Spring JMS Configuration

30

© 2011 IBM Corporation

Spring Message Producer

31

© 2011 IBM Corporation

Java EE Message Producer & JMS Abstraction

32

© 2011 IBM Corporation

Java EE Message Producer & JMS Abstraction

33

© 2011 IBM Corporation

Hacking the Java EE Platform - CDI Extensions  Activated by dropping jars on the application classpath  Loaded by the java.util.ServiceLoader SPI  Integrate with container through container lifecycle events by –Register additional beans, interceptors and decorators –Injecting dependencies into its own objects –Introduce custom scope with backing context –Augment or override bean annotation-based metadata with other source  Tools/utilities, extending Java EE, integration with Java EE APIs, integrating with non-standard APIs, making Java EE features available in non-Java EE 34

© 2011 IBM Corporation

Spring Ecosystem

35

© 2011 IBM Corporation

CDI Landscape

Implementations

Weld

Portable Extensions

Runtimes

CanDI

Tools

36

© 2011 IBM Corporation

CDI Ecosystem

37

© 2011 IBM Corporation

Spring & Java EE Coexistence  Integration with Java EE APIs – Spring beans can be injected into JSF Managed Beans – Spring beans can be referenced in EL with no JSF Backing beans – Spring JmsTemplate can be used on top of raw JMS API for convenience – Spring Listeners similar to EJB MDBs especially JCA rather than JMS listeners – Hibernate validator standardized as Bean Validation (JSR 303) – Spring 3 supports excellent bi-directional integration with EJBs – CDI and Spring Integration through the Spring Bridge to CDI  Native support for Java EE – Java EE5 and Java EE6 annotations supported by Spring – Spring can use JPA / Hibernate natively  Application server integration – DataSources can use application server QoS like pooling, transactions, statement caching, debugging, monitoring and security

38

© 2011 IBM Corporation

Java EE coexistence with Spring

39

© 2011 IBM Corporation

Birds Eye View

40

© 2011 IBM Corporation

References

 Evolution of Java EE http://en.wikipedia.org/wiki/Java_EE_version_history  Java EE 6 Tutorial http://download.oracle.com/javaee/6/tutorial/doc/  Spring Docs http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/  Spring Projects http://www.springsource.org/projects  Miscellaneous CDI Extensions https://github.com/softwaremill/softwaremill-common  Migrating Spring to Java EE – https://github.com/paulbakker/migrating-spring-to-javaee – http://ocpsoft.com/java/spring-to-java-ee-a-migration-guide-cdi-jsf-jpa-jta-ejb/  CDI- Spring Bridge – http://rick-hightower.blogspot.com/2011/04/cdi-and-spring-living-in-harmony.html – http://niklasschlimm.blogspot.com/2011/08/jsr-299-cdi-interceptors-for-spring.html – http://niklasschlimm.blogspot.com/2011/08/jsr-299-cdi-decorators-for-spring-beans.html  Best practices integrating Spring with WebSphere Application Server – http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.htm  What’s new in Spring 3.1 http://static.springsource.org/spring/docs/3.1.x/spring-frameworkreference/htmlsingle/spring-framework-reference.html#new-in-3.1

41

© 2011 IBM Corporation

References continued

 SEAM 3 http://seamframework.org/Seam3  CODI http://myfaces.apache.org/extensions/cdi/  Weld http://seamframework.org/Weld  CanDI http://www.caucho.com/resin/candi/  OpenWebBeans http://openwebbeans.apache.org/owb/index.html

42

© 2011 IBM Corporation