Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI 
Mario-Leander Reimer 
mario-leander.reimer@qawar...
2| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
This talkwil...
3| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
A<<Applicati...
4| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Whywouldyouw...
5| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
6| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Annotation b...
7| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Usageofcusto...
8| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
XML basedwir...
9| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
FactoryBeans...
10| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Usageofprop...
11| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Implementat...
12| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Programmati...
13| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
UsageofSpri...
14| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Spring XML ...
15| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Unit andmod...
16| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Wewerefaced...
17| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
18| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
19| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
All new Jav...
20| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Individual ...
21| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Basic Sprin...
22| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Bothtechnol...
23| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
@Stereotype...
24| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Migrate*-co...
25| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
XML based b...
26| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
XML based b...
27| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Thereisnodi...
28| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Property in...
29| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Migrating S...
30| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Migrating S...
31| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
The CDI way...
32| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Are Alterna...
33| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
The migrati...
34| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Programmati...
35| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Improvedapp...
36| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Directusage...
37| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
ReplacingSp...
38| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
Andtherewas...
39| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
28 daysand3...
40| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
28 daysand3...
41| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 
LessonsLear...
QUANTENSPRUNG DANK ANDERSDENKEN
Nächste SlideShare
Wird geladen in …5
×

Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI

2.285 Aufrufe

Veröffentlicht am

This talk is a detailed case study about the migration of a JSF-based web application from Spring 3 to Java EE 7 and CDI. It is presented at the JavaOne 2014 conference.

At first sight this didn’t seem to be too difficult. Both technologies are based on similar concepts and provide similar mechanisms for dependency injection (DI). So migrating pure annotation based bean wiring from Spring to CDI was obvious and straight forward.
But the deeper we looked into the source code the more Spring specific code we found with no direct and easy mapping in neither of JEE7, EJB3 or CDI available. Some of the problems and challenges we were confronted with were:
- How to migrate XML based bean wirings?
- How to migrate FactoryBeans?
- How to migrate AspectJ based AOP proxies?
- How to implement Spring profiles for environment based wiring?
- How to implement custom bean scopes?
- How to implement custom Spring XML schema notations and wiring?
- How to migrate code that is built against Spring APIs?
- How to migrate unit test based on Spring Test?
To answer these questions the talk will present the patterns and strategies used to map, transform and migrate the different concepts from Spring 3 to JEE7with CDI. The talk will discuss the changes and implications of the migration on the system’s architecture.

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI

  1. 1. Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI Mario-Leander Reimer mario-leander.reimer@qaware.de QAware
  2. 2. 2| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer This talkwill … Give a brief overview of the system’s architecture Try to explain the rationale behind the migration Outline differences and similarities between both technologies Show patternsandstrategiesused during the migration to translate the different concepts Discuss implications on the system’s architecture Highlight problems, challenges and lessons learned
  3. 3. 3| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer A<<Application Cluster>> AIR LoaderMechanicA<<System>> AIR CentralA<<Subsystem>> MaintenanceA<<System>> AIR RepositoryI<<Subsystem>> Apache SolrA<<Client>> AIR ClientI<<Subsystem>> .NET WPFA<<Subsystem>> Solr ExtensionsA<<Subsystem>> DefectsA<<Subsystem>> Flat RatesA<<Subsystem>> Service BulletinsServiceTechnicianA<<Ext. System>> 3rd Party ApplicationA<<Subsystem>> AIR Fork DLLA<<Subsystem>> AIR Call DLLLaunchI<<Subsystem>> Spring FrameworkI<<Subsystem>> JEE 5A<<System>> AIR ControlI<<Subsystem>> JenkinsA<<Subsystem>> DocumentsA<<Subsystem>> VehiclesA<<Subsystem>> MeasuresBackend Databasesand SystemsA<<Subsystem>> Repair OverviewA<<Subsystem>> MasterdataA<<Subsystem>> JSF Web UIA<<Subsystem>> REST APIIndependentWorkshopA<<Client>> BrowserSearch andDisplayA<<Ext. System>> 3rd Party iOS AppA<<Subsystem>> AIR iOS LibA<<Subsystem>> DefectsA<<Subsystem>> Flat RatesA<<Subsystem>> Service BulletinsI<<Subsystem>> Spring FrameworkA<<Subsystem>> DocumentsA<<Subsystem>> PartsA<<Subsystem>> WS ClientsA<<Subsystem>> File StorageA<<Subsystem>> Solr AccessA<<Subsystem>> ProtocollA<<Subsystem>> WatchlistA<<Subsystem>> MasterdataA<<Subsystem>> RetrofitsAIR DBDocumentStorageA<<Ext. System>> AIR BusI<<Ext. System>> Backend SystemsQueryA<<Subsystem>> VehiclesExecuteLoad400 GBSolr IndexA<<Subsystem>> Maintenance
  4. 4. 4| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Whywouldyouwanttomigratea stableandrunningsystem? The shortanswer: IT governance. The longanswer: JEE nowprovidesthesame functionalityandisa standard Easy andcostefficientmigrationtofutureJEE versions Lowercostsforweb infrastructureandapplicationoperations Easy applicationmaintenanceby*-shorecompanies Noadditional vendorsupportrequired, noadditional costs
  5. 5. 5| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
  6. 6. 6| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Annotation basedwiringofcomponentsusingconstructorinjection
  7. 7. 7| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer UsageofcustomSpring annotationsformoreexpressiveness
  8. 8. 8| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer XML basedwiringofcomponentsforSpring specificbeansandmorecomplexcomponents
  9. 9. 9| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer FactoryBeanstobuildbeaninstanceswithregularJava code
  10. 10. 10| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Usageofpropertyplaceholdersupporttoinjectconfigurationvalues
  11. 11. 11| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Implementation ofAspectJbasedproxiesforcrosscuttingconcerns
  12. 12. 12| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer ProgrammaticbeanlookupusingtheRegistry patternandtheApplicationContext
  13. 13. 13| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer UsageofSpring beanprofilesforenvironmentspecificbeanconfigurations
  14. 14. 14| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Spring XML namespacesforsyntacticsugar
  15. 15. 15| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Unit andmoduletestsheavilyuseandrelyon theSpring Testing framework
  16. 16. 16| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Wewerefacedwithmorequestionsthanwehadanswersfor How to migrate basic annotation based bean wiring? How to migrate XML based bean wiring and factory beans? How to migrate Spring property placeholder support? How to migrate AspectJ based AOP proxies? How to migrate programmatic bean lookups? How to migrate Spring bean profiles? How to migrate custom Spring XML namespaces? How to migrate code that is built against Spring APIs? How to migrate unit test based on Spring Test?
  17. 17. 17| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
  18. 18. 18| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer
  19. 19. 19| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer All new Java EE 7 Maven Coordinates
  20. 20. 20| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Individual Mavenmodulesasmainunitofmigration ReplaceSpring annotationsandwiringswithCDI equivalent ReplaceXML contextdefinitionswithbeans.xml Optional: adjustcomponentstobenefitfromCDI Find and/orbuildsubstitutesforSpring specificfeatures Adjustunitandintegrationtests
  21. 21. 21| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Basic Spring toCDI annotationmigrationisstraightforward, withsubtledifferences Caution: Spring andCDI havea different defaultscope! CDI usesclientproxiesper default(exceptfor@Dependent), in Spring youhavetodo thisexplicitly. This mightinfluenceyourwiringstyle. Becarefulwithfinal. Spring Annotation CDI Annotation @Component(„myBean“)  @Named(„myBean“) @Scope(„singleton“)  @ApplicationScoped @Scope(„prototype“)  @Dependent @Scope(„request“)  @RequestScoped @Scope(„session“)  @SessionScoped @Autowired  @Inject Default Default
  22. 22. 22| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Bothtechnologiessupport@Qualifiertodistinguishvariousimplementations Tip: do not use@Namedtoqualifyyourcomponentsin CDI, use custom@Qualifierannotationsinstead.
  23. 23. 23| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer @Stereotype istheCDI equivalenttocustom@Componentannotations Tip: check the@Target annotationoftheCDI stereotype, and includeMETHODso itcanbeappliedto@Producesmethods.
  24. 24. 24| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Migrate*-components.xml tobeans.xml Tip: useCDI 1.1 bean-discovery-mode=„annotated“ astheequivalenttoSpring‘scomponentscan.
  25. 25. 25| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer XML based bean wiring as well as factory beans are migrated to Producer methods -Factory beanscanalso usedependencyinjection -Support forlifecycle -Constructorinjection -Nestedfactorybean
  26. 26. 26| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer XML based bean wiring as well as factory beans are migrated to Producer methods
  27. 27. 27| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer ThereisnodirectequivalenttoSpring‘s@Value(„${some.property}“) annotation
  28. 28. 28| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Property injectionsupportforCDI usingtheDeltaSpikeConfigurationMechanism Tip: havea lookat Apache DeltaSpikebeforeyoustartbuilding yourowncustomCDI extensionsformissingfeatures.
  29. 29. 29| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Migrating Spring AOP using @Interceptor and @InterceptorBindingannotations Activate aspectsandautoproxy relevant beans Pointcutforall publicmethodsin classesannotatedwith@Service Pointcutforall publicmethodsin classesannotatedwith@Repository
  30. 30. 30| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Migrating Spring AOP using @Interceptor and @InterceptorBindingannotations
  31. 31. 31| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer The CDI way for programmatic bean lookup improved our code enormously BeanManageristhe~ equivalenttoApplicationContext MigratedApplicationContextAwarestaticregistryclasstousetheBeanManagerinstead Advice: don‘tuseBeanManagerdirectly.It‘stoolowlevel. Don‘tusea staticregistryeither. Gruesometestability! Tip: ifstaticaccesstocontextualreferencesisreallyrequired, usetheDeltaSpikeBeanProviderimplementation.
  32. 32. 32| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Are Alternatives theequivalenttoSpring‘sbeandefinitionprofiles? Almost. Problem: Alternatives needtobeactivatedin thebean.xml Not suitableforenvironmentspecific, dynamicactivation. Usea CDI extensiontovetoannotatedtype ifprofileisnot active. Alternative: UsetheDeltaSpikeProjectStagemechanism.
  33. 33. 33| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer The migrationofourcustomSpring XML namespacesseemedtobea challenge Create instanceoftype FiniteStateMachinewithgivenID asbeanname Enumtype definitions Create transitioninstancewithgivenproperties Bean lookupbynameforactioninstancetoexecute
  34. 34. 34| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Programmaticapproach: combineBuilderpatternwitha producermethod Usedfornamedaction beanlookup
  35. 35. 35| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Improvedapproach: usea CDI extensiontoreadXML filesandcreateFSM beans Createsinstances, usestheBuilderfromfirstapproach
  36. 36. 36| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer DirectusageofsimplifiedJMS 2.0 API insteadofSpring‘sJmsTemplate Sending Receiving
  37. 37. 37| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer ReplacingSpring‘sTesting Framework was painfulanda lotofwork SpringJUnit4ClassRunnerMockitoJUnitRunner This workreallypaidof Simplifiedunittestswithbetterisolation decreasedexecutiontime Different approachesandtestrunnersforCDI testsavailable: JglueCDI-Unit: @RunWith(CdiRunner.class) DeltaSpikeTest-Control: @RunWith(CdiTestRunner.class) Arquillian: @RunWith(Arquillian.class) Testing a CDI enabledJAR in isolationiscomplexandlaborious(orjust didn‘twork)
  38. 38. 38| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer Andtherewas a lotmorecodetomigrate MigratedSpring taskexecutionandschedulingfuntionalityto@AsyncmethodsorJEE7 ManagedExecutorService The JPA persistencecodemigrationwentsmoothly Migratedpersistence.xml fromJPA 1.0 to2.1 Simple JPA unittestsusingDBUnitfortestdatasetup The JSF web layermigrationwas quitetedious Homogenizeannotationusage: replacedFacesbeanannotationswithCDI equivalent(e.g. @ManagedBean@Named) RemovedRegistry basedlookupofservicefacadeinstances Migratedandsimplifiedunittests, thisalso improvedtestquality
  39. 39. 39| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 28 daysand300K LOC later…
  40. 40. 40| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer 28 daysand300K LOC later… … wehadtheAIR Central web applicationfullymigratedandrunningon Glassfishv4. Migration effortswereordersofmagnitudelowerthaninitiallyestimatedandanticipated! The standaloneAIR Loaderapplicationswerenexttomigrate: usingCDI fromJava SE, evenmorecomplexSpring XML namespace, comprehensiveusageofSpring JDBC.
  41. 41. 41| JavaOne2014 | Migrating a JSF-based web application from Spring 3 to Java EE 7 and CDI| M.-Leander Reimer LessonsLearnedandResumé JEE7 andCDI havedefinitelycaughtupon Spring Therewas noSpring featurethatcouldnot bemigrated Someconvenienceisstill missing, but CDI provideslightweightandeasy touseextensionmechanisms, thereisgrowingsupportfromtheOpen Source community. Questionandrethinkestablishedpatternsandbestpractices More carefulwhenusingandbindingtoa specificframework
  42. 42. QUANTENSPRUNG DANK ANDERSDENKEN

×