Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Bert Ertman
Fellow at Luminis in the Netherla
                                 nds
JUG Leader for NLJUG and a Java
       ...
Who is this talk
     for?
You are using old school
Spring and wonder how to
move forward
Java EE seems to be hot again,
s...
Why listen to us?


         d endless         ..worked
We’ve ha
                       extensively with
   Ja va EE vs.
 ...
some disclaimers:

Not looking for another holy war
No shootout
No silver bullets
Why migrate?

                        Spring is
                       proprietary
                       technology
Upgra...
This m ight have been competitive in the past...
But now we want THIS!
Let’s get



a couple of misunderstandings



             out of the way



          first...
Isn’t Java EE too fat?

Startup times with application deployed
  JBoss AS 7 ~2 seconds
  Glassfish V3 ~4 seconds
  Tomcat...
Isn’t Java EE too fat?

Startup times with application deployed
  JBoss AS 7 ~2 seconds
  Glassfish V3 ~4 seconds
        ...
Isn’t Java EE
  supposed to be evil?

Based on 2004 rhetorics

Ever heard of the fable of the tortoise and
the hare?
But I need dependency
         injection?

Java EE 6 introduced CDI
  More powerful,
  contextual DI model
  Makes the pla...
But I must have AOP!

    Really?
You love getting
  your code all
                     Or are you just
asymmetric and
   ...
Can I still do unit
       testing?

It took a while to get
 there, but yes Java EE
 supports testing as well
do I need heavy tooling?
NO!

do I need heavy tooling?
Ca pabilities comparison
                               Spring                            JavaEE
Capability
  Dependency  ...
Apparently,



it can all be done using



plain vanilla light weight



      Java EE
rm -Rf spring*
Sure it would be
fun, but not very
    realistic
We need a recipe that
 moves us forward
    step by step
Old school Spring app

lots of complex XML, no annotations
old / outdated ORM solution
  JDBC Templates, Kodo, Toplink, et...
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
Upgrade Spring version

Upgrade Spring runtime (replace JAR files)
No code / configuration changes
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
replace old frameworks
                                                  within Spring
presentaton
   layer



           ...
replace old frameworks
                                                  within Spring
presentaton
   layer



           ...
replace old frameworks
                                                  within Spring
presentaton
   layer



           ...
replace old frameworks
                                                  within Spring
presentaton
   layer



           ...
W hat about Spring APIs we
don’t want to change yet?

   Jdbc Templates
   REST Templates
   Task Scheduling
   etc.
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
Using Spring and Java EE
      side-by-side

Disclaimer 1: this is just to give an idea, this
is not a production ready fr...
Spring application
Servlet Container

  myapp.war
                       Spring container
    TX manager




             ...
Java EE application
Java EE 6 application server
   CDI / EJB container

                                                 ...
Mixed
Java EE 6 application server

   CDI / EJB container
                                                  myapp.war
   ...
run Spring within
                                                    Java EE container
presentaton
   layer



          ...
add Java EE code
                                                    keep old Spring code
presentaton
   layer



        ...
Dependency Injection
Spring already supports
JSR-330
Use @Inject anywhere you use
@AutoWired
CDI could be almost a drop-in...
Encapsulate Spring with
         CDI

 Write a CDI extension that
  bootstraps the Spring
  container
  looks up Spring Be...
The Spring DAO
JSF / CDI bean




                 Here we don’t
                 want to know
                 about Spring
CDI extension example




https://github.com/paulbakker/migrating-spring-to-javaee
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
presentaton
   layer
                                                entirely replace Spring

                            ...
presentaton
   layer
                                            entirely replace Spring

                                ...
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...
Come on, are you telling me EJBs are cool now?




                   You bet!

                                  Just lik...
The Spring DAO
The Java EE alternative




     btw -
   this is an
     EJB! :)
Dealing with lazy loading
Many Spring apps use the Open-
EntityManager-In-View pattern
EJB has the Extended Persistence
Co...
LazyInitializationException
Fixing lazy loading
Detached entities

Spring DAOs are stateless (all singletons)
Load > edit > save needs a merge
With an Extended PU we don’t
Migration path
Template addict?


Hooked to JDBC Templates!?

           Hmm, let’s start
          the old discussion
           whether...
Using JD BC Templates

1. Can b e injected with simple
   Producer method
2.It is n ot relying on Spring
   container
3.so...
Template producer example
Migration path
1. Upgrade Spring version
2.Replace old frameworks
   (ORM, web framework)
   within Spring
3.Run Spring an...
Removing Dependencies
Our classpath just has to
contain APIs, no framework
classes
From ~40 dependencies to just:
What about testing?




Spring is pretty good at this



        Java EE was not
How to test this?
CDI alternatives
What about
 JPA code?
Ar quillian

Create micro deployments
      using an API

    Run tests in real containers
Arquillian example
Wrap up
Is it all worth it?




blissful ignorance or painful reality ?!
Is there life after Spring?

 We believe that there is always
 room for innovation
   Ideally through Open Source
 When it...
Other sessions of interest
Arquillian: The
Extendable Enterprise Test
                             Introducing Contexts an...
contact us:
Bert Ertman
bert.ertman@lum
                inis.eu
Paul Bakker
paul.bakker@lum
                inis.eu
JavaOne 2011: Migrating Spring Applications to Java EE 6
Upcoming SlideShare
Loading in …5
×

of

JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 1 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 2 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 3 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 4 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 5 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 6 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 7 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 8 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 9 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 10 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 11 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 12 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 13 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 14 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 15 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 16 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 17 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 18 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 19 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 20 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 21 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 22 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 23 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 24 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 25 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 26 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 27 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 28 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 29 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 30 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 31 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 32 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 33 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 34 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 35 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 36 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 37 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 38 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 39 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 40 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 41 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 42 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 43 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 44 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 45 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 46 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 47 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 48 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 49 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 50 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 51 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 52 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 53 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 54 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 55 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 56 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 57 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 58 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 59 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 60 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 61 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 62 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 63 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 64 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 65 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 66 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 67 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 68 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 69 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 70 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 71 JavaOne 2011: Migrating Spring Applications to Java EE 6 Slide 72
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

80 Likes

Share

Download to read offline

JavaOne 2011: Migrating Spring Applications to Java EE 6

Download to read offline

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.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

JavaOne 2011: Migrating Spring Applications to Java EE 6

  1. 1. Bert Ertman Fellow at Luminis in the Netherla nds JUG Leader for NLJUG and a Java Champion @bertertman Paul Bakker Senior developer at Luminis Tech nologies @pbakker
  2. 2. 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?
  3. 3. Why listen to us? d endless ..worked We’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 war No shootout No silver bullets
  5. 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. 6. This m ight have been competitive in the past...
  7. 7. But now we want THIS!
  8. 8. Let’s get a 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 seconds Java 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 seconds Java 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 rhetorics Ever heard of the fable of the tortoise and the 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 just asymmetric 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 JavaEE Capability 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 using plain vanilla light weight Java EE
  19. 19. rm -Rf spring*
  20. 20. Sure it would be fun, but not very realistic
  21. 21. We need a recipe that moves us forward step by step
  22. 22. 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.)
  23. 23. Migration path 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
  24. 24. Migration path 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
  25. 25. Upgrade Spring version Upgrade Spring runtime (replace JAR files) No code / configuration changes
  26. 26. Migration path 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
  27. 27. replace old frameworks within Spring presentaton layer Web MVC @AutoWired business Spring beans layer Tasks @AutoWired @AutoWired Data / Integration Spring JDBC layer Kodo JMS beans Templates
  28. 28. replace old frameworks within Spring presentaton layer Web MVC @AutoWired business Spring beans layer Tasks @AutoWired @AutoWired Data / Integration Spring JDBC layer JPA JMS beans Templates
  29. 29. replace old frameworks within Spring presentaton layer JSF @AutoWired business Spring beans layer Tasks @AutoWired @AutoWired Data / Integration Spring JDBC layer JPA JMS beans Templates
  30. 30. replace old frameworks within Spring presentaton layer JSF Don’t touch Spring @AutoWired specific APIs yet business Spring beans layer Tasks @AutoWired @AutoWired Data / Integration Spring JDBC layer JPA JMS beans Templates
  31. 31. W hat about Spring APIs we don’t want to change yet? Jdbc Templates REST Templates Task Scheduling etc.
  32. 32. Migration path 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
  33. 33. Using Spring and Java EE side-by-side Disclaimer 1: this is just to give an idea, this is not a production ready framework! Disclaimer 2: this is a migration path. Not the way you should build your next application...
  34. 34. Spring application Servlet Container myapp.war Spring container TX manager ORM Spring   beans AOP Spring   beans
  35. 35. Java EE application Java EE 6 application server CDI / EJB container myapp.war TX manager Interceptors Security JPA CDI  beans Session  beans
  36. 36. Mixed Java 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 container presentaton layer JSF @AutoWired business f Spring beans d stuf layer Ad here... Tasks @AutoWired Data / Integration Spring JDBC layer JPA JMS beans Templates
  38. 38. add Java EE code keep old Spring code presentaton layer JSF @AutoWired @Inject business layer Spring beans EJB CDI Tasks @AutoWired @Inject Data / Integration Spring JDBC layer JPA JMS beans Templates
  39. 39. Dependency Injection Spring already supports JSR-330 Use @Inject anywhere you use @AutoWired CDI could be almost a drop-in replacement 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 example https://github.com/paulbakker/migrating-spring-to-javaee
  44. 44. Migration path 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
  45. 45. presentaton layer entirely replace Spring JSF @AutoWired @Inject business Spring beans EJB CDI layer Tasks @AutoWired @Inject Data / Integration Spring JDBC layer JPA JMS beans Templates
  46. 46. presentaton layer entirely replace Spring JSF @Inject @Inject business EJB CDI EJB Timers layer @Inject @Inject Data / Integration Spring JDBC layer JPA MDB Templates
  47. 47. 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
  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 loading Many Spring apps use the Open- EntityManager-In-View pattern EJB has the Extended Persistence Context
  52. 52. LazyInitializationException
  53. 53. Fixing lazy loading
  54. 54. Detached entities Spring DAOs are stateless (all singletons) Load > edit > save needs a merge With 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 Templates 1. Can b e injected with simple Producer method 2.It is n ot relying on Spring container 3.some extra dependencies though
  58. 58. Template producer example
  59. 59. Migration path 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
  60. 60. Removing Dependencies Our classpath just has to contain APIs, no framework classes From ~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 quillian Create 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 interest Arquillian: The Extendable Enterprise Test Introducing Contexts and Platform (24121) Dependency Injection 1.1 Beginning Java EE 6 (22480) (23421) Java EE 6: The Cool Parts CDI Today and Tomorrow (21641) (19941) Java EE and Spring/MVC Enterprise JavaBeans Shoot-out (24161) Technology 3.2 (23180) Rethinking Best Practices Hacking Java EE: CDI with Java EE 6 (21622) Extension Writing n00b to l33t (23805)
  71. 71. contact us: Bert Ertman bert.ertman@lum inis.eu Paul Bakker paul.bakker@lum inis.eu
  • RebeccaKryszczynski

    Nov. 27, 2021
  • DavideOlisti

    May. 14, 2020
  • gavinollameghana

    Apr. 23, 2020
  • AlexsanderLuizdeQuei

    Apr. 1, 2018
  • RusselCalvin

    Oct. 5, 2017
  • prafullkotecha

    Aug. 24, 2017
  • FelipeCastilla

    Apr. 3, 2017
  • achillar

    Apr. 3, 2017
  • jlanento

    Apr. 3, 2017
  • OndrejMihlyi

    Apr. 2, 2017
  • riccardomassera

    Apr. 2, 2017
  • BurakHamiolu

    Feb. 27, 2017
  • Abhijitgogoi5

    Feb. 13, 2017
  • SumantaPramanik

    Feb. 6, 2017
  • TamianNingayo

    Dec. 26, 2016
  • JatinAneja6

    Aug. 2, 2016
  • baybatu

    May. 21, 2016
  • DatevDemir

    Apr. 3, 2016
  • HernanGabrielSoliman

    Mar. 27, 2016
  • TiagoSantos336

    Mar. 13, 2016

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.

Views

Total views

147,114

On Slideshare

0

From embeds

0

Number of embeds

90,902

Actions

Downloads

1,250

Shares

0

Comments

0

Likes

80

×