41
© 2011 IBM Corporation © 2011 IBM Corporation 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

Java EE vs Spring Framework

  • Upload
    kelapure

  • View
    22.271

  • Download
    3

Embed Size (px)

DESCRIPTION

This session compares the Spring and Java EE stacks in terms of Web frameworks. It re-examines the motivations behind the Spring framework and explores the emergence of the Java EE programming model to meet the challenges posed. The presentation provides insight into when Spring and/or Java EE is appropriate for a building Web applications and if they can coexist.

Citation preview

Page 1: Java  EE vs Spring Framework

© 2011 IBM Corporation© 2011 IBM Corporation

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

Page 2: Java  EE vs Spring Framework

© 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

Page 3: Java  EE vs Spring Framework

© 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

Page 4: Java  EE vs Spring Framework

© 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

Page 5: Java  EE vs Spring Framework

© 2011 IBM Corporation

J2EE Java EE Specifications

Project JPE

EJB 1.0

Servlet 2.1

May 98

Enterprise Application

J2EE 1.2

EJB 1.1

Servlet 1.1

JSP 1.1

JMS 1.0.2

JDBC 2.0

JNDI 1.2

JAF 1.0

JTA 1.0

JTS 0.95

JavaMail 1.1

Dec 99

10 specs

Robust

Scalable

J2EE 1.3

EJB 2.0 (CMP,

MDB, local EJBs )

Servlet 2.3

(Events, Filters)

JSP 1.2

JDBC 2.1

JCA* 1.0

JAAS* 1.0

JAXP* 1.0

Sept 01

13 specs

Web Services

J2EE 1.4

EJB 2.1 (Timers

Pluggable JMS)

Servlet 2.4

JSP 2.0

Web Services*

JMX Mgmt.*

J2EE Deploy*

JACC*,

JAAS*

JAX-RPC*,

JAXR*

JSTL*

Nov03

20 specs

Ease of Development

JEE 5.0

EJB 3.0 (POJO components)

JPA 1.0* (POJO persistence)

JSF 1.2*

Servlet 2.5

JSP 2.1 (Common EL)

JAXB*, SAAJ*, StAX*, JAX-WS*

Web Services (POJO components, Protocol Independence)

Annotations (IoC), Injection

May06 24specs

* Introduced in spec.

Page 6: Java  EE vs Spring Framework

© 2011 IBM Corporation

Evolution of J2EEJava EE6 (Dec 09)

New specs (JAX-RS, CDI, Bean Validation)

Prune dead wood– EJB 2.x, JAX-RPC, JAXR, JEE App.

Deploy, JEE App mgmt.

Extensibility– Easy Framework Pluggability (web

fragments & CDI Extensions)

Enhanced ease of development– POJO annotation based Servlets, – Asynchronous processing (Servlet 3.0 &

EJB 3.1)– EJB 3.1

• EJB-in-WAR, No-interface view, Singleton, EJB-lite, Timers

– Contextual Dependency Injection (CDI)– RESTful services– Portable JNDI names

– JSF2.0• Facelets, built-in-AJAX, Skins, Annotations,

Resource handling• Simplified Navigation, Easier custom

components, View & Page scopes• Bookmarkable pages, Project Stage,

Expanded event model– JPA 2.0

• Mapping enhancements, JPAQL, Criteria Query API, Pessimistic locking

Profiles reduce platform size – Web Profile 12 specs

Vendor support– WebSphere AS 8– JBOSS AS 7– Oracle WebLogic 11g– Glassfish 3

6

Page 7: Java  EE vs Spring Framework

© 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

Page 8: Java  EE vs Spring Framework

© 2011 IBM Corporation

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

8

1.0

• Dependency injection

• POJO-oriented development

• Declarative AOP & transactions

• MVC framework

2.0

• Problem-specific XML

• Extensible configuration

• Bean scoping• Groovy,

JRuby, and BeanShell

• JSP tag library• Java 5

autoboxing and generics

2.5

• Annotation-driven wiring

• Automatic bean configuration

• New annotation-driven MVC framework

• JUnit 4-based integration testing

3.0• JSR-330 “at

inject”• New Spring

Expression Language

• First-class REST support

• Java-based configuration

• Several new Spring MVC features

• Support for JSR-303 declarative validation

• Annotation-based background and scheduled jobs

3.1• A new “c”

namespace• Configuration

profiles• Unified

property resolution

• Java configuration features

• Servlet 3.0 support

• Declarative caching

• Spring MVC enhancements

Page 9: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Framework

9

Lightweight dependency injection

Aspect oriented

Layered application & container framework

Well defined modules on top of the core container

NOT an all-or-nothing solution

Page 10: Java  EE vs Spring Framework

© 2011 IBM Corporation10

Birds Eye View

Page 11: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Framework Features/APIs Overview

11

Page 12: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Business Component

12

Page 13: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring XML for Business Component Injection

13

Page 14: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring XML for Business Component Injection

14

Page 15: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Java Based Configuration

15

Page 16: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Java Based Configuration

16

Page 17: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE Interceptor vs. Spring Aspects

17

Page 18: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Injection

18

Page 19: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Injection – Spring configuration

19

Page 20: Java  EE vs Spring Framework

© 2011 IBM Corporation20

Facelet Component

JSF 2 vs. Spring MVC Front Controller

Page 21: Java  EE vs Spring Framework

© 2011 IBM Corporation21

Facelet

JSF 2 vs. Spring MVC Front Controller

Page 22: Java  EE vs Spring Framework

© 2011 IBM Corporation22

EntityJSF Event Handler

JSF 2 vs. Spring MVC Front Controller

Page 23: Java  EE vs Spring Framework

© 2011 IBM Corporation23

JSF 2 vs. Spring MVC

Spring MVC JSP

Page 24: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring MVC Configuration

24

Page 25: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Controller

25

Page 26: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring MVC web.xml configuration

26

Page 27: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Scheduling

27

Page 28: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Scheduling

28

Page 29: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE vs. Spring Messaging

29

Page 30: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring JMS Configuration

30

Page 31: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Message Producer

31

Page 32: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE Message Producer & JMS Abstraction

32

Page 33: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE Message Producer & JMS Abstraction

33

Page 34: Java  EE vs Spring Framework

© 2011 IBM Corporation34

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

Page 35: Java  EE vs Spring Framework

© 2011 IBM Corporation

Spring Ecosystem

35

Page 36: Java  EE vs Spring Framework

© 2011 IBM Corporation

CDI Ecosystem Snapshot

36

Implementations

Weld CanDI

RuntimesPortable Extensions

Tools

Page 37: Java  EE vs Spring Framework

© 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

37

Page 38: Java  EE vs Spring Framework

© 2011 IBM Corporation

Java EE coexistence with Spring

38

Page 39: Java  EE vs Spring Framework

© 2011 IBM Corporation39

Birds Eye View

Page 40: Java  EE vs Spring Framework

© 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-framework-reference/htmlsingle/spring-framework-reference.html#new-in-3.1

40

Page 41: Java  EE vs Spring Framework

© 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

41