VS. And the Winner is Java User Group Switzerland, Bern, 23.05.2012 - - PowerPoint PPT Presentation

vs
SMART_READER_LITE
LIVE PREVIEW

VS. And the Winner is Java User Group Switzerland, Bern, 23.05.2012 - - PowerPoint PPT Presentation

VS. And the Winner is Java User Group Switzerland, Bern, 23.05.2012 Simon Martinelli / @simas_ch simas GmbH - Moosentli 7 - 3235 Erlach - 032 544 88 88 - sm@simas.ch - www.simas.ch Agenda Introduction Dependeny Injection


slide-1
SLIDE 1

VS.

And the Winner is …

Java User Group Switzerland, Bern, 23.05.2012 Simon Martinelli / @simas_ch

simas GmbH - Moosentli 7 - 3235 Erlach - 032 544 88 88 - sm@simas.ch - www.simas.ch

slide-2
SLIDE 2

Agenda

  • Introduction
  • Dependeny Injection
  • Differences
  • Conclusion
slide-3
SLIDE 3

1995 2012 2001 COBOL/HOST J2EE / Java EE 2010 2004 Spring 1995 2012 2001 JCA 2010 2004 AD DS 2007 Java Persistence API DB / DWH AD JEE

Development

SBB ACS simas GmbH

Training

Berner Fachhochschule Software Schule Schweiz Medical Technology Center

AD JEE = Architektur und Design Java EE / AD DS = Architektur und Design verteilter Systeme

About me

slide-4
SLIDE 4

Introduction

slide-5
SLIDE 5

No Flame War

slide-6
SLIDE 6

Poll on JAXenter in November 11

  • Spring oder Java EE?
  • Ich bevorzuge Java EE (46%)
  • Ich bevorzuge Spring (34%)
  • Je nach Anwendungsfall das eine oder das andere

(15%)

  • Es gibt bessere Alternativen (5%)

377 Teilnehmer

slide-7
SLIDE 7

The Books

2002 2004

slide-8
SLIDE 8

History

1999 2011 2009 2003 1.2

Servlets JSP EJB JMS

2001 1.3

CMP JCA

1.4

Web Services Management Deployment Async JCA

2005 5

Ease of Dev Annotations JSF EJB 3 JPA WS

J2EE / Java EE Spring Framework 1.0

DI

2004 2006 6

Profiles Pruning Extensibility EJB Lite REST CDI

1.2

Java 5

2.0 2007 2.5

Annotations JEE5

3.0

JSR-330 REST

0.9

slide-9
SLIDE 9

Spring vs. J2EE

slide-10
SLIDE 10

Really versus?

slide-11
SLIDE 11

Some Quotes

  • «Frameworks like Spring are really just a bridge

between the mistakes of the J2EE past and the success of Java EE future»

The age of frameworks is over, Cameron McKenzie

  • «Due to Springs early success and adaption,

Java EE is pushed to greatly simplify the Java EE programming model…»

Spring vs. Java EE and why I don’t care, Eberhard Wolff

slide-12
SLIDE 12

Dependency Injection

slide-13
SLIDE 13

Java EE 6 DI

JSR 330: Dependency Injection for Java JSR 299: Contexts and Dependency Injection for the Java EE platform JSR 318: Enterprise JavaBeans 3.1

slide-14
SLIDE 14

CDI Injection

public class MyService { } public class AnotherService { @Inject private MyService myService; } The Bean The Injection Point Could also be a constructor or a setter

slide-15
SLIDE 15

CDI Qualifiers

@Asynchronous public class AsyncService implements MyService { ... } public class AnotherService { @Inject @Synchronous private MyService myService; } @Synchronous public class SyncService implements MyService { ... } Two Implementations of the same interface Two implementations of the same interface Injection must be qualified

slide-16
SLIDE 16

CDI Producers

public class MyService { public MyService(A a) { // ... } } public class MyServiceProducer { @Produces public MyService createMyService(A a) { return new MyService(a); } } public class AnotherService { @Inject private MyService myService; } Producer Method to create instance A will be injected!

slide-17
SLIDE 17

CDI Interceptors

@Interceptor @Transactional public class TransactionInterceptor { @AroundInvoke public Object manageTransaction(InvocationContext ctx) { // ... } } @InterceptorBinding public @interface Transactional { } public class MyService { @Transactional public void foo() { // ... } } The Interceptor The Annotation A Transactional Method

slide-18
SLIDE 18

CDI Events

public class MyService { @Inject private Event<LoggedInEvent> loggedInEvent; public void login(String username, String password) { loggedInEvent.fire(new LoggedInEvent(username)); // ... } } public class LoggedInObserver { public void afterLogin(@Observers LoggedInEvent event) { // ... } } The Event Object Fire the Event The Listener Called Synchronous!

slide-19
SLIDE 19

Asynchronous Events

@Stateless public class LoggedInObserver { @Asynchronous public void afterLogin(@Observers LoggedInEvent event) { // ... } } The Listener as EJB Called Asynchronous!

slide-20
SLIDE 20

CDI Extensions

Source: http://planet.jboss.org/post/seam_next_announcement

slide-21
SLIDE 21

Spring DI: XML based

<beans> <bean id="myService" class="service.MyService"/> <bean id="anotherService" class="service.AnotherService"> <property name="myService" ref="myService"/> </bean> </beans>

public class AnotherService { private MyService myService; public void setMyService(MyService myService) { this.myService = myService; } }

The Injection Point Could also be a constructor

slide-22
SLIDE 22

Spring DI: Annotation based

public class AnotherService { @Autowired private MyService myService; }

public class AnotherService { @Inject private MyService myService; }

<beans> <context:annotation-config/> </beans> The Injection Point Could also be a constructor or a setter JSR-330 Spring Annotations

public class AnotherService { @Resource private MyService myService; }

JSR-250

slide-23
SLIDE 23

Spring DI: Java based

@Configuration public class AppConfig { @Bean public MyService myService() { return new MyService(); } <beans> <bean id="myService" class="service.MyService"/> </beans>

slide-24
SLIDE 24

Scopes

Application Session Conversation Request Java EE Spring EJB General Stateful = Prototype Stateless x Singleton = Singleton CDI Web RequestScoped = Request ConversationScoped (=) Spring Web Flow SessionScoped = Session ApplicationScoped = Singleton Dependant x x Global Session (only for Portlets)

slide-25
SLIDE 25

Differences

slide-26
SLIDE 26

Java EE is a Specification

slide-27
SLIDE 27

Spring is an Ecosystem

Spring Framework Spring Security Spring Integration Spring Batch Spring Data Spring Web Flow Spring Web Services Spring Mobile Spring Social Spring Andorid Spring Roo Spring BlazeDS Integration Spring AMQP …

slide-28
SLIDE 28

Spring uses Java EE

  • Do you really need a wrapper around these APIs?

JPA JMS JMX JCA Mail …

slide-29
SLIDE 29

Defaults

@Stateless public class MyService { public void foo() { ... } } @Service public class MyService { @Transactional public void foo() { ... } } Defaults to @TransactionAttribute(REQUIRED)

slide-30
SLIDE 30

Deployment

Java EE Applikation Spring Applikation Java EE App Server Tomcat TomEE Spring Framework Java EE App Server

CDI Apache OpenWebBeans EJB Apache OpenEJB Javamail Apache Geronimo JavaMail JPA Apache OpenJPA JSF Apache MyFaces JTA Apache Geronimo Transaction Connector Apache Geronimo Connector JMS Apache ActiveMQ Web Services Apache CXF

TomEE TomEE Plus

slide-31
SLIDE 31

Are App Servers still heavy?

Source: Antonio Goncalves

Size

slide-32
SLIDE 32

Are App Servers still slow?

Source: Antonio Goncalves

slide-33
SLIDE 33

Interoperability

  • Web
  • Spring Beans can be used with JSF
  • CDI
  • Integration through Spring Bridge to CDI
  • Metadata
  • Spring supports Java EE annotations
  • i.e. @PersistenceContext
slide-34
SLIDE 34

Integration Testing

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class MyTest { @Autowired private MyService myService; } @RunWith(Arquillian.class) public class MyTest { @EJB private MyService myService; }

www.jboss.org/arquillian

+

slide-35
SLIDE 35

Summary

Topic Java EE Spring Framework Framework Specification based Ecosystem Defaults Conventions over Configuration No Default Behavior Dependency Injection CDI Spring Container JSR 330 but not CDI! Transactions EJB AOP / Annotations Web Framework JSF Spring Web MVC AOP Interceptors XML AspectJ Integration Testing Arquillian (non standard) Spring Test Framework Deployment Part of the Platform Part of the Application Independency Several Vendors VMware

slide-36
SLIDE 36

Conclusion

slide-37
SLIDE 37

What is missing in Java EE?

Batch

  • Spring Batch
  • JSR-352

ACL based Security

  • Spring Security
  • No Java EE support planned

NoSQL (Big Data)

  • Spring Data
  • No Java EE support planned
slide-38
SLIDE 38

It’s a Draw!

  • Java EE 6 is a mature, easy to use

framework inspired by Spring

  • Unfortunately a lot of companies are still using

application servers < Java EE 6

  • Spring offers solutions for common problems

like ACL based Security, Batch or NoSQL

slide-39
SLIDE 39

The Future: Java EE 7

Batch

  • JSR-352 Java Batch

Cloud

  • Multitenancy

Clean Up

  • JSF and CDI

Simplification

  • JMS

Enhancements

  • CDI Java SE Bootstrap

and JPA Integration

slide-40
SLIDE 40

Q&A