vs
play

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


  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

  2. Agenda  Introduction  Dependeny Injection  Differences  Conclusion

  3. About me Development SBB ACS simas GmbH Spring COBOL/HOST J2EE / Java EE 1995 2001 2004 2010 2012 Training AD JEE Berner Fachhochschule AD DS Software Schule Schweiz Medical Technology Center DB / DWH JCA Java Persistence API 1995 2001 2007 2012 2004 2010 AD JEE = Architektur und Design Java EE / AD DS = Architektur und Design verteilter Systeme

  4. Introduction

  5. No Flame War

  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

  7. The Books 2002 2004

  8. History 0.9 1.0 1.2 2.0 2.5 3.0 DI Java Annotations JSR-330 5 JEE5 REST 1.3 1.4 1.2 5 6 Servlets CMP Web Services Ease of Dev Profiles JSP JCA Management Annotations Pruning EJB Deployment JSF Extensibility JMS Async JCA EJB 3 EJB Lite JPA REST WS CDI 1999 2001 2003 2004 2005 2006 2007 2009 2011 Spring Framework J2EE / Java EE

  9. Spring vs. J2EE

  10. Really versus?

  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

  12. Dependency Injection

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

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

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

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

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

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

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

  20. CDI Extensions Source: http://planet.jboss.org/post/seam_next_announcement

  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> The Injection Point public class AnotherService { Could also be a constructor private MyService myService; public void setMyService(MyService myService) { this.myService = myService; } }

  22. Spring DI: Annotation based <beans> <context:annotation-config/> </beans> Spring Annotations The Injection Point Could also be a public class AnotherService { constructor or a setter @Autowired private MyService myService; } JSR-330 JSR-250 public class AnotherService { public class AnotherService { @Inject @Resource private MyService myService; private MyService myService; } }

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

  24. Request Scopes Conversation Session Application 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)

  25. Differences

  26. Java EE is a Specification

  27. Spring is an Ecosystem Spring Security Spring Integration Spring Batch Spring Data Spring Web Flow Spring Framework Spring Web Services Spring Mobile Spring Social Spring Andorid Spring Roo Spring BlazeDS Integration Spring AMQP …

  28. Spring uses Java EE  Do you really need a wrapper around these APIs? JPA JCA JMS Mail JMX …

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

  30. Deployment Java EE Applikation Spring Applikation TomEE Spring Framework Java EE App Server Java EE App Tomcat Server TomEE TomEE Plus CDI Apache OpenWebBeans Connector Apache Geronimo Connector EJB Apache OpenEJB JMS Apache ActiveMQ Javamail Apache Geronimo JavaMail Web Services Apache CXF JPA Apache OpenJPA JSF Apache MyFaces JTA Apache Geronimo Transaction

  31. Are App Servers still heavy? Size Source: Antonio Goncalves

  32. Are App Servers still slow? Source: Antonio Goncalves

  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

  34. Integration Testing @RunWith(Arquillian.class) public class MyTest { + @EJB private MyService myService; } www.jboss.org/ arquillian @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class MyTest { @Autowired private MyService myService; }

  35. Summary Topic Java EE Spring Framework Framework Specification based Ecosystem Defaults Conventions over No Default Behavior Configuration 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

  36. Conclusion

  37. What is missing in Java EE? ACL based Security  Spring Security Batch  No Java EE support planned  Spring Batch  JSR-352 NoSQL (Big Data)  Spring Data  No Java EE support planned

  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

  39. The Future: Java EE 7 Clean Up Simplification  JSF and CDI  JMS Cloud  Multitenancy Enhancements Batch  CDI Java SE Bootstrap  JSR-352 Java Batch and JPA Integration

  40. Q&A

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend