JavaOne 2011: Migrating Spring Applications to Java EE 6

123,660 views
134,320 views

Published on

The Spring Framework has no-doubt played a major role in evolving the way we write enterprise applications on the Java platform today. However, it is still a proprietary framework owned by a single company. The age of having to rely on such proprietary frameworks in order to develop decent enterprise applications is now over and Java EE 6 has become an even easier way to develop enterprise applications based on standards which makes it the best choice for any enterprise application. In this session you will experience how to migrate a typical full stack Spring application to a standards based, completely portable, Java EE 6 application including integration tests.

Published in: Technology, Education
14 Comments
64 Likes
Statistics
Notes
  • More than 5000 IT Certified ( SAP,Oracle,Mainframe,Microsoft and IBM Technologies etc...)Consultants registered. Register for IT courses at http://www.todaycourses.com Most of our companies will help you in processing H1B Visa, Work Permit and Job Placements
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi All, We are planning to start new devops online batch on this week... If any one interested to attend the demo please register in our website... For this batch we are also provide everyday recorded sessions with Materials. For more information feel free to contact us : siva@keylabstraining.com. For Course Content and Recorded Demo Click Here : http://www.keylabstraining.com/devops-online-training-tutorial
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • ios online training http://www.keylabstraining.com/mobile-apps/ios-online-training
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Java: The Complete Reference, Ninth Edition --- http://amzn.to/1Udwjd0
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • JAVA: The Ultimate Beginner's Guide! --- http://amzn.to/1UI3aVN
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
123,660
On SlideShare
0
From Embeds
0
Number of Embeds
74,916
Actions
Shares
0
Downloads
1,164
Comments
14
Likes
64
Embeds 0
No embeds

No notes for slide

JavaOne 2011: Migrating Spring Applications to Java EE 6

  1. 1. Bert ErtmanFellow at Luminis in the Netherla ndsJUG Leader for NLJUG and a Java Champion @bertertmanPaul BakkerSenior developer at Luminis Tech nologies @pbakker
  2. 2. Who is this talk for?You are using old schoolSpring and wonder how tomove forwardJava EE seems to be hot again,should you jump on thistrain?You love the J2EE Design andDevelopment book; but is itstill actual?
  3. 3. Why listen to us? d endless ..workedWe’ve ha extensively with Ja va EE vs. J2EE, Spring and Spring modern Java EE dis cussions.....not employed by ..and we’re no an application Rod Johnson server vendor groupies either
  4. 4. some disclaimers:Not looking for another holy warNo shootoutNo silver bullets
  5. 5. Why migrate? Spring is proprietary technologyUpgrading fromold school Spring requires a lot of work anyway Why not take it to the standard?
  6. 6. This m ight have been competitive in the past...
  7. 7. But now we want THIS!
  8. 8. Let’s geta couple of misunderstandings out of the way first...
  9. 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 secondsJava EE 6 WAR file < 100kb
  10. 10. Isn’t Java EE too fat?Startup times with application deployed JBoss AS 7 ~2 seconds Glassfish V3 ~4 seconds Our favorite quote: Tomcat 6 + Spring ~4 secondsJava EE 6 WAR file < 100kb in the Java EE spec “Nowhere does it say that Java EE servers should be heavy weight and slow...”
  11. 11. Isn’t Java EE supposed to be evil?Based on 2004 rhetoricsEver heard of the fable of the tortoise andthe hare?
  12. 12. But I need dependency injection?Java EE 6 introduced CDI More powerful, contextual DI model Makes the platform extensible in a standard way
  13. 13. But I must have AOP! Really?You love getting your code all Or are you justasymmetric and using AOP light unreadable? a.k.a. Spring AOP a.k.a. (Java EE) Interceptors?
  14. 14. Can I still do unit testing?It took a while to get there, but yes Java EE supports testing as well
  15. 15. do I need heavy tooling?
  16. 16. NO!do I need heavy tooling?
  17. 17. Ca pabilities comparison Spring JavaEECapability Dependency CDI Spring Container Injection EJB Transactions AOP / annotations JSF Web framework Spring Web MVC Interceptors AOP AspectJ (limited to Spring beans) JMS JMS / CDI Messaging JPA Data Access JDBC templates / other ORM / JPA RESTful Web JAX-RS Spring Web MVC (3.0) Services Arquillian * Integration testing Spring Test framework tion * Not part of the Java EE specifica
  18. 18. Apparently,it can all be done usingplain vanilla light weight Java EE
  19. 19. rm -Rf spring*
  20. 20. Sure it would befun, but not very realistic
  21. 21. We need a recipe that moves us forward step by step
  22. 22. Old school Spring applots of complex XML, no annotationsold / outdated ORM solution JDBC Templates, Kodo, Toplink, etc.deprecated extension based Web MVC(SimpleFormController, etc.)
  23. 23. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  24. 24. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  25. 25. Upgrade Spring versionUpgrade Spring runtime (replace JAR files)No code / configuration changes
  26. 26. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  27. 27. replace old frameworks within Springpresentaton layer Web MVC @AutoWiredbusiness Spring beans layer Tasks @AutoWired @AutoWiredData / Integration Spring JDBC layer Kodo JMS beans Templates
  28. 28. replace old frameworks within Springpresentaton layer Web MVC @AutoWiredbusiness Spring beans layer Tasks @AutoWired @AutoWiredData / Integration Spring JDBC layer JPA JMS beans Templates
  29. 29. replace old frameworks within Springpresentaton layer JSF @AutoWiredbusiness Spring beans layer Tasks @AutoWired @AutoWiredData / Integration Spring JDBC layer JPA JMS beans Templates
  30. 30. replace old frameworks within Springpresentaton layer JSF Don’t touch Spring @AutoWired specific APIs yetbusiness Spring beans layer Tasks @AutoWired @AutoWiredData / Integration Spring JDBC layer JPA JMS beans Templates
  31. 31. W hat about Spring APIs wedon’t want to change yet? Jdbc Templates REST Templates Task Scheduling etc.
  32. 32. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  33. 33. Using Spring and Java EE side-by-sideDisclaimer 1: this is just to give an idea, thisis not a production ready framework! Disclaimer 2: this is a migration path. Not the way you should build your next application...
  34. 34. Spring applicationServlet Container myapp.war Spring container TX manager ORM Spring   beans AOP Spring   beans
  35. 35. Java EE applicationJava EE 6 application server CDI / EJB container myapp.war TX manager Interceptors Security JPA CDI  beans Session  beans
  36. 36. MixedJava EE 6 application server CDI / EJB container myapp.war CDI  beans Session  beans TX manager Interceptors Security JPA Spring TX manager Spring   ORM AOP beans Spring   beans
  37. 37. run Spring within Java EE containerpresentaton layer JSF @AutoWiredbusiness f Spring beans d stuf layer Ad here... Tasks @AutoWiredData / Integration Spring JDBC layer JPA JMS beans Templates
  38. 38. add Java EE code keep old Spring codepresentaton layer JSF @AutoWired @Injectbusiness layer Spring beans EJB CDI Tasks @AutoWired @InjectData / Integration Spring JDBC layer JPA JMS beans Templates
  39. 39. Dependency InjectionSpring already supportsJSR-330Use @Inject anywhere you use@AutoWiredCDI could be almost a drop-inreplacement for Spring DI but opens up much more powerful options
  40. 40. 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
  41. 41. The Spring DAO
  42. 42. JSF / CDI bean Here we don’t want to know about Spring
  43. 43. CDI extension examplehttps://github.com/paulbakker/migrating-spring-to-javaee
  44. 44. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  45. 45. presentaton layer entirely replace Spring JSF @AutoWired @Injectbusiness Spring beans EJB CDI layer Tasks @AutoWired @InjectData / Integration Spring JDBC layer JPA JMS beans Templates
  46. 46. presentaton layer entirely replace Spring JSF @Inject @Injectbusiness EJB CDI EJB Timers layer @Inject @InjectData / Integration Spring JDBC layer JPA MDB Templates
  47. 47. The TX layerMigrate Spring TX and DAOs to EJBThe TX manager is in the app serverAn EJB is transactional by defaultEJB has JPA integration
  48. 48. Come on, are you telling me EJBs are cool now? You bet! Just like EJBs are just Spring beans, container but without managed the container POJOs configuration
  49. 49. The Spring DAO
  50. 50. The Java EE alternative btw - this is an EJB! :)
  51. 51. Dealing with lazy loadingMany Spring apps use the Open-EntityManager-In-View patternEJB has the Extended PersistenceContext
  52. 52. LazyInitializationException
  53. 53. Fixing lazy loading
  54. 54. Detached entitiesSpring DAOs are stateless (all singletons)Load > edit > save needs a mergeWith an Extended PU we don’t
  55. 55. Migration path
  56. 56. Template addict?Hooked to JDBC Templates!? Hmm, let’s start the old discussion whether or not to use ORM... Phase 1: denial Phase 2: migrate ;-)
  57. 57. Using JD BC Templates1. Can b e injected with simple Producer method2.It is n ot relying on Spring container3.some extra dependencies though
  58. 58. Template producer example
  59. 59. Migration path1. Upgrade Spring version2.Replace old frameworks (ORM, web framework) within Spring3.Run Spring and Java EE container side by side4.Replace Spring entirely5.Remove Spring container
  60. 60. Removing DependenciesOur classpath just has tocontain APIs, no frameworkclassesFrom ~40 dependencies to just:
  61. 61. What about testing?Spring is pretty good at this Java EE was not
  62. 62. How to test this?
  63. 63. CDI alternatives
  64. 64. What about JPA code?
  65. 65. Ar quillianCreate micro deployments using an API Run tests in real containers
  66. 66. Arquillian example
  67. 67. Wrap up
  68. 68. Is it all worth it?blissful ignorance or painful reality ?!
  69. 69. Is there life after Spring? We believe that there is always room for innovation Ideally through Open Source When it flies, bring it back to the spec!
  70. 70. Other sessions of interestArquillian: TheExtendable Enterprise Test Introducing Contexts andPlatform (24121) Dependency Injection 1.1Beginning Java EE 6 (22480)(23421) Java EE 6: The Cool PartsCDI Today and Tomorrow (21641)(19941) Java EE and Spring/MVCEnterprise JavaBeans Shoot-out (24161)Technology 3.2 (23180) Rethinking Best PracticesHacking Java EE: CDI with Java EE 6 (21622)Extension Writing n00b tol33t (23805)
  71. 71. contact us:Bert Ertmanbert.ertman@lum inis.euPaul Bakkerpaul.bakker@lum inis.eu

×