45
1 Java EE and Spring Framework Shootout Rohit Kelapure WebSphere Application Server Caching Architect Apache OpenWebBeans Committer IBM http://wasdynacache.blogspot.com/ http://www.linkedin.com/in/rohitkelapure http://twitter.com/rkela Recording: http://www.parleys.com/#st=5&id=2819&sl=0 Session ID = TDP-1163

2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

Embed Size (px)

DESCRIPTION

Spring Framework

Citation preview

Page 1: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

1

Java EE and Spring Framework Shootout

Rohit Kelapure

WebSphere Application Server Caching Architect

Apache OpenWebBeans Committer

IBM

http://wasdynacache.blogspot.com/

http://www.linkedin.com/in/rohitkelapure

http://twitter.com/rkela

Recording: http://www.parleys.com/#st=5&id=2819&sl=0

Session ID = TDP-1163

Page 2: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

2

Please Note

IBM's statements regarding its plans, directions, and intent are subject to change or withdrawal at IBM's sole discretion. Information regarding potential future products is intended to outline our general product direction and it should not be relied on in making a purchasing decision. The information mentioned regarding potential future products is not a commitment, promise, or legal obligation to deliver any material, code or functionality. Information about potential future products may not be incorporated into any contract. The development, release, and timing of any future features or functionality described for our products remains at our sole discretion. Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.

Page 3: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

3

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

Spring to Java EE migration

Conclusion

Page 4: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

4

J2EE Java EE Specifications

* Introduced in spec.

Page 5: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

5

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

Page 6: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

6

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

Page 7: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

7

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

Page 8: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

8

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

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: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

9

Birds Eye View

Page 10: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

10

Java EE vs. Spring Framework Features/APIs

Page 11: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

11

Java EE vs. Spring Business Component

Page 12: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

12

Spring XML for Business Component Injection

Page 13: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

13

Spring XML for Business Component Injection

Page 14: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

14

Spring Java Based Configuration

Page 15: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

15

Spring Java Based Configuration

Page 16: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

16

Java EE Interceptor vs. Spring Aspects

Page 17: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

17

Java EE vs. Spring Injection

Page 18: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

18

Java EE vs. Spring Injection

Page 19: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

19

JSF 2 vs. Spring MVC Front Controller

Facelet Component

Page 20: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

20

JSF 2 vs. Spring MVC Front Controller

Facelet

Page 21: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

21

JSF 2 vs. Spring MVC Front Controller

Entity

Page 22: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

22

JSF 2 vs. Spring MVC Spring MVC JSP

Page 23: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

23

Spring MVC Configuration

Page 24: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

24

Spring Controller

Page 25: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

25

Spring MVC web.xml configuration

Page 26: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

26

Java EE vs. Spring Scheduling

Page 27: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

27

Java EE vs. Spring Scheduling

Page 28: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

28

Java EE vs. Spring Messaging

Page 29: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

29

Spring JMS Configuration

Page 30: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

30

Spring Message Producer

Page 31: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

31

Java EE Message Producer & JMS Abstraction

Page 32: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

32

Java EE Message Producer & JMS Abstraction

Page 33: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

33

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 34: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

34

Spring Ecosystem

Page 35: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

35

CDI Ecosystem Snapshot

Implementations

Weld CanDI

Runtimes Portable Extensions

Tools

Page 36: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

36

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

Page 37: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

37

Best Practices integrating Spring WAS

Presentation tier considerations

– Web MVC & Portlet

Data access considerations

– Using JDBC native connections

– Transactions, JPA & JMS

Spring Security Considerations

– Bypassing WAS security

Integration & Management considerations

– Registering Spring Mbeans in the application server

– Classloaders

Design Considerations

– Unmanaged threads

– Scheduling & Threadpools

Page 38: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

38

Java EE coexistence with Spring

Page 39: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

39

Migrating Spring to Java EE 6

1. Upgrade Spring version

2. Replace old frameworks (ORM, Web Framework) within Spring

3. Run Spring and Java EE container side by side

4. Replace Spring entirely

5. Remove Spring container

Page 40: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

40

Myths of Java EE

EJBs are heavy weight

EJBs are hard to test

EJBs are not portable

EJBs are slow

EJBs are not scalable

EJBs are too complex

EJBs are hard to integrate with

Web Frameworks and POJOs

EJBs are hard to configure

EJBs are hard to migrate

EJBs are hard to develop

EE application servers are

"bloated“

J2EE and EJB2 sucked! “That

was eight years ago! Is this really

your best shot?”

Application server portability is a

myth!

Page 41: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

41

Birds Eye View

Page 42: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

42

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

Page 43: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

43

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

Page 44: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

44

We love your Feedback!

Don’t forget to submit your Impact session and speaker

feedback! Your feedback is very important to us, we use it to

improve our conference for you next year.

Go to impactsmartsite.com from your mobile device

From the Impact 2012 Online Conference Guide:

– Select Agenda

– Navigate to the session you want to give feedback on

– Select the session or speaker feedback links

– Submit your feedback

Page 45: 2012 04-06-v2-tdp-1163-java e-evsspringshootout-final

45

© IBM Corporation 2012. All Rights Reserved.

IBM, the IBM logo, ibm.com are trademarks or registered

trademarks of International Business Machines Corp.,

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 at

“Copyright and trademark information” at

www.ibm.com/legal/copytrade.shtml.

Copyright and Trademarks