java ee 6 best practices for migrating spring to wtf ?!?
TRANSCRIPT
![Page 1: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/1.jpg)
JAVA EE 6
Best Practices for Migrating
Spring to
WTF ?WTF ?!?!?
![Page 2: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/2.jpg)
Bert Ertman
Fellow at Luminis in the Netherlands
JUG Leader for NLJUG and a Java Champion
![Page 3: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/3.jpg)
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?
![Page 4: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/4.jpg)
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...
![Page 5: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/5.jpg)
Why migrate?
Spring is proprietary technology
Upgrading from old school Spring requires a lot of work anyway
Why not take it to the standard?
![Page 6: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/6.jpg)
Scenario A
![Page 7: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/7.jpg)
But now we want this
![Page 8: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/8.jpg)
Let’s get a couple of
misunderstanding out of the way
first...
![Page 9: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/9.jpg)
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
![Page 10: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/10.jpg)
But I need Dependency
Injection• Java EE 6 introduced
CDI
•More powerful, contextual DI model
•Makes the platform extensible in a standard way
![Page 11: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/11.jpg)
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?
![Page 12: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/12.jpg)
Do I need heavy tooling?
![Page 13: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/13.jpg)
Capabilities comparison
Capability Spring JavaEEDependency
InjectionSpring Container CDI
Transactions AOP / annotations EJB
Web framework Spring Web MVC JSF
AOP AspectJ (limited to Spring beans) Interceptors
Messaging JMS JMS / CDI
Data Access JPA / JDBC templates / other ORM JPA
RESTful Web Services
Spring Web MVC (3.0) JAX-RS
Integration testing Spring Test framework Arquillian *
* Not part of the Java EE specification
![Page 14: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/14.jpg)
It can all be done using plain vanilla light weight Java
EE
![Page 15: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/15.jpg)
rm -Rf spring*
?
![Page 16: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/16.jpg)
Sure it would be fun!
realistic?
![Page 17: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/17.jpg)
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.)
![Page 18: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/18.jpg)
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
![Page 19: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/19.jpg)
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
![Page 20: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/20.jpg)
Upgrade Spring version
Upgrade Spring runtime (replace JAR files)
No code / configuration changes
![Page 21: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/21.jpg)
Migration Path
1.Upgrade Spring version
2.Replace old frameworks (ORM, web framework) within Spring
3.Add Java EE code, keep old Spring code
4.Replace Spring entirely
5.Remove Spring container
![Page 22: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/22.jpg)
Replace old frameworks within Spring
presentaton
layer
Data / Integratio
nlayer
Web MVC
Tasks
Spring JDBC Templates
Kodo
@AutoWired
businesslayer
JMS beans
@AutoWired
@AutoWired
JPA
JSF Don’t touch Spring specific
APIs yet
Spring beans
![Page 23: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/23.jpg)
Migration Path
1.Upgrade Spring version
2.Replace old frameworks (ORM, web framework) within Spring
3.Add Java EE code, keep old Spring code
4.Replace Spring entirely
5.Remove Spring container
![Page 24: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/24.jpg)
myapp.warSpring container
Servlet Container
Spring application
Spring beans
Spring beans
TX
TX
m
an
ag
er
man
ag
er
AO
PA
OP
OR
MO
RM
![Page 25: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/25.jpg)
Java EE 6 application server
CDI / EJB container
myapp.war
CDI beans
Session beans
TX
man
ag
er
TX
man
ag
er
Secu
rity
Secu
rity
Inte
rcep
tors
Inte
rcep
tors
JPA
JPA
Java EE application
![Page 26: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/26.jpg)
Java EE 6 application server
CDI / EJB container
myapp.warCDI beansSession beans
TX
man
ag
er
TX
man
ag
er
Secu
rity
Secu
rity
Inte
rcep
tors
Inte
rcep
tors
JPA
JPA
Spring containe
rSpring beans
Spring beans
TX
TX
m
an
ager
man
ager
AO
PA
OP
OR
MO
RM
Mixed
![Page 27: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/27.jpg)
Run Spring within a Java EE containerpresentat
onlayer
Data / Integratio
nlayer
Spring beans
Tasks
Spring JDBC Templates
businesslayer
JMS beans
@AutoWired
@AutoWired
JPA
JSF
![Page 28: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/28.jpg)
Add Java EE code, keep old Spring code
presentaton
layer
Data / Integratio
nlayer
Spring beans
Tasks
Spring JDBC Templates
businesslayer
JMS beans
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
![Page 29: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/29.jpg)
The Spring DAO
![Page 30: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/30.jpg)
Spring configuration
![Page 31: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/31.jpg)
JSF / CDI bean
Here we don’t want to know about Spring
![Page 32: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/32.jpg)
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
![Page 33: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/33.jpg)
CDI extension example
![Page 34: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/34.jpg)
Migration Path
1.Upgrade Spring version
2.Replace old frameworks (ORM, web framework) within Spring
3.Add Java EE code, keep old Spring code
4.Replace Spring entirely
5.Remove Spring container
![Page 35: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/35.jpg)
Replace Spring entirelypresentat
onlayer
Data / Integratio
nlayer
Spring beans
Tasks
Spring JDBC Templates
businesslayer
JMS beans
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
![Page 36: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/36.jpg)
Replace Spring entirelypresentat
onlayer
Data / Integratio
nlayer
EJB Timers
businesslayer
MDB
@AutoWired
@AutoWired
JPA
JSF
EJB CDI
@Inject
@Inject
Spring JDBC Templates
![Page 37: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/37.jpg)
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
![Page 38: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/38.jpg)
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...
![Page 39: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/39.jpg)
DAO
Spring
![Page 40: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/40.jpg)
DAO configuration
![Page 41: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/41.jpg)
The Java EE alternative
EJB
![Page 42: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/42.jpg)
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
![Page 43: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/43.jpg)
LazyInitializationException
![Page 44: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/44.jpg)
Fixing lazy loading
Keeps an EntityManager open as long a the bean exists
![Page 45: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/45.jpg)
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 ;-)
![Page 46: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/46.jpg)
Using JDBC Template within
Java EECan be injected with simple Producer method
Possible because it is not relying on Spring container
some extra dependencies though
![Page 47: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/47.jpg)
Template producer example
![Page 48: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/48.jpg)
Migration Path
1.Upgrade Spring version
2.Replace old frameworks (ORM, web framework) within Spring
3.Add Java EE code, keep old Spring code
4.Replace Spring entirely
5.Remove Spring container
![Page 49: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/49.jpg)
Removing dependencies
Our classpath just has to contain APIs, no framework classes
From ~40 dependencies to just 1
![Page 50: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/50.jpg)
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
![Page 51: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/51.jpg)
How to test this?
![Page 52: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/52.jpg)
Arquillian
Create a micro deployment using an API
Deploy to a real application server
Run tests in the server
![Page 53: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/53.jpg)
Arquillian example
![Page 54: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/54.jpg)
![Page 55: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/55.jpg)
Is it all worth it?
![Page 56: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/56.jpg)
Is there life after Spring?
We believe that there is always room for innovation
Ideally through Open Source
If it flies, bring it back to the spec!
![Page 57: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/57.jpg)
There is more!
• 4-part article series on Jboss web site
• Step-by-step migration of Pet Clinic sample application
• http://www.howtojboss.com
![Page 58: JAVA EE 6 Best Practices for Migrating Spring to WTF ?!?](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697c0281a28abf838cd6faa/html5/thumbnails/58.jpg)
thank you