1 / 58

JAVA EE 6

Best Practices for Migrating Spring to. JAVA EE 6. WTF ?!?. Bert Ertman Fellow at Luminis in the Netherlands JUG Leader for NLJUG and a Java Champion. Who is this talk for?. You are using old school Spring and wonder how to move forward

liv
Download Presentation

JAVA EE 6

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Best Practices for Migrating Spring to JAVA EE 6 WTF ?!?

  2. Bert Ertman Fellow at Luminis in the Netherlands JUG Leader for NLJUG and a Java Champion

  3. Who is this talk for? • You are using old school Spring and wonder how to move forward • Java EE seems to be hot again, should you jump on this train? • You love the J2EE Design and Development book; but is it still actual?

  4. Why listen to us? • We’re not working for an application server vendor • We’re no Rod Johnson groupies either • We’ve worked extensively with J2EE, Spring and modern Java EE • Had endless Java EE vs. Spring discussions...

  5. Why migrate? • Spring is proprietary technology • Upgrading from old school Spring requires a lot of work anyway • Why not take it to the standard?

  6. Scenario A

  7. But now we want this

  8. Let’s get a couple of misunderstanding out of the way first...

  9. Isn’t Java EE too fat? • Startup times with application deployed • JBoss AS 7 ~2 seconds • Glassfish V3 ~4 seconds • Tomcat 6 + Spring ~4 seconds • Java EE 6 WAR file < 100kb

  10. But I need Dependency Injection • Java EE 6 introduced CDI • More powerful, contextual DI model • Makes the platform extensible in a standard way

  11. But I need AOP! • Really? • You love getting your code all asymmetric and unreadable? • Or are you just using AOP light a.k.a. Spring AOP a.k.a. (Java EE) Interceptors?

  12. Do I need heavy tooling?

  13. Capabilities comparison * Not part of the Java EE specification

  14. It can all be done using plain vanilla light weight Java EE

  15. rm -Rf spring* ?

  16. Sure it would be fun! realistic?

  17. Typical old school Spring app • lots of complex XML, no annotations • old / outdated ORM solution • (JDBC Templates, Kodo, Toplink etc.) • deprecated extension based Web MVC (SimpleFormController etc.)

  18. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Run Spring and Java EE container side by side • Replace Spring entirely • Remove Spring container

  19. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Run Spring and Java EE container side by side • Replace Spring entirely • Remove Spring container

  20. Upgrade Spring version • Upgrade Spring runtime (replace JAR files) • No code / configuration changes

  21. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Add Java EE code, keep old Spring code • Replace Spring entirely • Remove Spring container

  22. Don’t touch Spring specific APIs yet Web MVC Tasks Spring JDBC Templates Kodo JMS beans JPA JSF Spring beans Replace old frameworks within Spring presentaton layer @AutoWired business layer @AutoWired @AutoWired Data / Integration layer

  23. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Add Java EE code, keep old Spring code • Replace Spring entirely • Remove Spring container

  24. TX manager AOP ORM Spring application Servlet Container myapp.war Spring container Spring beans Spring beans

  25. Interceptors JPA TX manager Security Java EE application Java EE 6 application server CDI / EJB container myapp.war CDI beans Session beans

  26. Spring container TX manager ORM AOP Spring beans Spring beans Interceptors JPA TX manager Security Mixed Java EE 6 application server CDI / EJB container myapp.war CDI beans Session beans

  27. Spring beans Tasks Spring JDBC Templates JMS beans JPA JSF Run Spring within a Java EE container presentaton layer @AutoWired business layer @AutoWired Data / Integration layer

  28. Spring beans Tasks Spring JDBC Templates JMS beans JPA JSF EJB CDI Add Java EE code, keep old Spring code presentaton layer @AutoWired @Inject business layer @Inject @AutoWired Data / Integration layer

  29. The Spring DAO

  30. Spring configuration

  31. JSF / CDI bean Here we don’t want to know about Spring

  32. Encapsulate Spring with CDI • Write a CDI extension that • bootstraps the Spring container • looks up Spring Beans in the Spring container and publish in CDI context

  33. CDI extension example

  34. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Add Java EE code, keep old Spring code • Replace Spring entirely • Remove Spring container

  35. Spring beans Tasks Spring JDBC Templates JMS beans JPA JSF EJB CDI Replace Spring entirely presentaton layer @AutoWired @Inject business layer @Inject @AutoWired Data / Integration layer

  36. EJB Timers MDB JPA JSF EJB CDI Spring JDBC Templates Replace Spring entirely presentaton layer @AutoWired @Inject business layer @Inject @AutoWired Data / Integration layer

  37. The TX layer • Migrate Spring TX and DAOs to EJB • The TX manager is in the app server • An EJB is transactional by default • EJB has JPA integration

  38. Come on, are you telling me EJBs are cool now? • You bet! • EJBs are just container managed POJOs • Just like Spring beans, but without the container configuration...

  39. DAO Spring

  40. DAO configuration

  41. The Java EE alternative EJB

  42. Dealing with Lazy Loading • Many Spring apps use the Open-EntityManager-In-View pattern • EJB has the Extended Persistence Context • more explicit and more powerful

  43. LazyInitializationException

  44. Fixing lazy loading • Keeps an EntityManager open as long a the bean exists

  45. Template addict? • What if I’m hooked to JDBC Template? • Hmm, let’s start the old discussion about whether or not to use ORM • phase 1: denial • phase 2: eventually you will migrate ;-)

  46. Using JDBC Template within Java EE • Can be injected with simple Producer method • Possible because it is not relying on Spring container • some extra dependencies though

  47. Template producer example

  48. Migration Path • Upgrade Spring version • Replace old frameworks (ORM, web framework) within Spring • Add Java EE code, keep old Spring code • Replace Spring entirely • Remove Spring container

  49. Removing dependencies • Our classpath just has to contain APIs, no framework classes • From ~40 dependencies to just 1

  50. What about testing? Spring has always been great at testing • DI makes unit testing possible • Spring test framework makes testing within the Spring container possible • Flexible configuration for multi-environment testing

More Related