SlideShare a Scribd company logo
Spring Scala

Sneaking Scala into your corporation
Brought to you by Henryk Konsek / @hekonsek
About me

open source committer, evangelist and adopter
Apache Camel
Spring Scala (Spring Source aka VMware aka Pivotal)
7 years of professional experience
Artegence aka Filmweb
Asseco
Pitney Bowes
Java Black Belt
freelance consulting
About me

Hired by Red Hat (JBoss)
to work with JBoss Fuse stack:
Apache ServiceMix
Apache ActiveMQ
JBoss HornetQ
Apache Camel
Apache CXF

http://jboss.org/jbossfuse
1.
2.
3.
4.

This talk

Some context
What is Spring Scala
How to use Spring Scala
Why use Spring Scala
1. Some context
Inversion Of Control (IoC)
Dependency Injection (DI)
Spring
Spring guide for busy
developers
Defining dependency to be used in application:

@ of gr to
C ni u ai n
p bi c as Iv ie aC n iu ai n {
u lc l s no c Do of gr t o
@e nI vi ea i vi e a( {
Ba no cD o no cD o)
r tr n wI vi ea ( ;
e u n e n o cD o)
}
@e nI vi ee v c i v ie ev c( {
Ba no cS ri e no cS r ie )
r tr n wI vi ee v c( no cD o) ;
e u n e n o cS ri ei v ie a( )
}
}
Spring guide for busy
developers
Using the dependency in the application:

p bi c as Iv ie eo t ee ao {
u lc l s no c Rp rG nr t r
@n et
Ij c
pi ae Iv ie e vc i vi ee vc ;
rv t n oc Sr ie n oc S ri e
pb i Ls <n oc >i v ie Fr ot (n y a, i tm nh {
ul c it Iv i e no cs o Mn hi t er n o t)
I vi eu r qe y= I vi eu re .e rya )m nh m nh ;
n o cQ ey u r
n oc Q ei sy a(er . ot(o t)
r tr i vi ee vc . id no cs qe y ;
e u n n oc S ri ef nI v ie (u r)
}
}
2. What is Spring Scala

official project from Spring Source (aka VMware, aka Pivotal)
portfolio
API for defining beans in Scala
wrappers for existing Spring API (aka Pimp My Spring)
3. How to use Spring Scala
Defining beans
c as MS aa of g et ns Fn t oa Cn iu ai n {
l s y cl Cn i xe d u ci nl of g rt o
vl do =b a( ( ya ()
a a
en )M Do )
ba (( ye vc ( a( )
en ) MS ri ed o) )
}

define bean of type MyDao and bean of type MyService
MyDao is wired into MyService
Defining beans
c as MS aa of g et ns Fn t oa Cn iu ai n {
l s y cl Cn i xe d u ci nl of g rt o
vl do =b a( {
a a
en )
M Do )
ya(
}
ba ( {
en )
M Sr ie do )
y e vc (a ()
}
}

Notice functions!
Defining beans - lifecycle
c a s M s a e r k r o f g r t o e t n s F n t o a C n i u a i n{
l s e sg Bo eC ni u ai n xe d uc in l of gr to
ba (a e= "c i eq rk r) {
en n m
a tv mB o e"
v lb oe = nw Bo e Sr ie
a rk r
e r kr ev c
b oe .d Cn e tr "c :/ o ah s: 11 "
r k ra do nc o( t p/ lc lo t6 6 6)
b oe
rkr
}i i {
nt
_ sa t)
. t r(
}d sr y{
eto
_ so (
. t p)
}
}

We avoid hard-coding method names. We invoke them instead.
Accessing beans
v lc ne t= Fn t oa Cn iA p ia in ot x[ y cl Cn i]
a otx
u ci nl o fg pl ct oC n et MS aa o fg
v ls ri e= cn e tM Sr ie
a evc
o tx [y e vc ]
(Globally) Accessing beans
Config

o jc M Sa ao fg et n sF nt oa Cn i ua in{
b et y cl Cn i x ed u c in lo fg rt o
vl do =b a( ( ya ()
a a
en )M Do )
vl sr ie =b a (( ye vc ( a( )
a e vc
en )M S ri ed o) )
}

+ application bootstrap
o jc M Ap et ns Ap {
b et y p xe d p
nw Fn to aC n iA pi ai n ot x( .
e u ci nl of gp l ct oC ne t)
r gs eC ni u ai n( yc l Cn i)
e i tr of gr to s MS aa of g
}

= global access
M S a a o f g s r i e ) m S r i e e h d)
y cl C ni .e vc (. y ev cM to(

Or even global access on steroids!
i pr M Sa ao fg _
m ot y cl Cn i .
..
.
s ri e) mS ri e eh d)
e vc ( .y ev cM to (
Pimping your existing
contexts
v lx lo tx = nw Ca s ah mA pi ai n ot x( ca s ah ba sx l )
a m C ne t
e l sP tX l pl ct oC ne t "l sp t: en . m"
v ls aa ot x =
a c l Cn et
A pi ai no t xC ne so s tR cA pi ai n ot x( mC ne t
p l ct oC ne to v ri n. oi hp l ct oC ne t xl ot x)
v ls ri e= sa a ot x[ ye v c]
a evc
c lC ne t MS ri e

For those who aren't easily frightened by implicit conversions:
i pr o gs rn fa eo k sa ac ne t A p ia in ot x Cn es os _
m ot r .p ig r mw r. cl . ot x. pl ct o Cn et ov ri n.
v lx lo tx = nw Ca s ah mA pi ai n ot x(ca s ah ba sx l )
a m C ne t
e l sP tX l pl ct oC ne t"l sp t: en . m"
v ls ri e= xl o tx [y ev c ]
a evc
m Cn et M Sr ie
Scala friendly API #1
JmsTemplate

v lc ne to Fc o y: Cn et o Fc oy = ..
a o n ci na tr
o nc in at r
.
v lt ml t =n wJ se p ae cn et oF c oy
a e p ae
e mT ml t( o nc in at r)

Function callbacks instead of anonymous inner functions.
t ml t. ed"u u" {s si n Ss in =
e pa e sn(q ee)
e so : es o >
ss in ce tT x Ms ae "e l Wr d )
es o .r ae et es g (H lo o l"
}

Pattern matching friendly return types.
t ml t. ee v( q ee )m th {
e pa e rc ie "u u" ac
cs S m( :T xM sa e = pi tn mg t et
ae o em e t es g) > r nl (. eT x)
cs N n = p it n" o tx m sa er ci e"
ae o e > r n l( N et e sg e e vd)
}
Scala friendly API #2
JdbcTemplate

v lt ml t =n wJ bT m lt (a ao re
a e p ae
e dc ep ae d tS uc )

Functions instead of callbacks
v lt ml t. ur A da(S LC l gn FO U E" {
a e p ae qe yn Mp " EE T oi R M SR )
(e ut e, rw u )=
rs l St o Nm >
" d %"fr a (o Nm r sl St gt t ig 1)
%: s.o mt rw u , e u te .e Sr n ()
}

Scala collections instead of java.util API
v lu es :M pS r n, nR f =t ml t. u rF ra (S L C * FO U E"
a sr
a[ ti gA y e]
ep ae qe yo M p" EE T
R M SR )

Options instead of nulls
v lq ey =" EE T lg nF O UE W EE i =?
a ur
SL C oi RM S R H R d
"
v ll gn =t ml t .u rF rb e tS rn ]q ey , 1 m t h{
a oi
ep ae qe y oO jc [t ig ( ur
) ac
Sm (o i)
oe l gn
Nn = "e al L gn
oe > d fu to i"
}
Scala friendly API #3

Aspect Oriented Programming
Defining aspects as (anonymous inner) classes is overkill.
v ll ge Av c =
a o g rd ie
(e hd M to ,a g: A ry Ay e] t re :A y =
mt o : e hd rs r a[ n Rf , a g t n) >
l gd bg "x c tn m to { " m to . eN m)
o . eu (E eu ig e hd } , eh dg ta e
v ls vP it u =( :M t o, c Ca s_ )= m gt ae s at Wt (s v"
a a e on ct
m eh d : ls [] > . e Nm .t rs ih " ae )

What about wiring aspects into beans?
a vc t re (e M Sr i e o s vP it u ui g lg eA vc
d ie a gt n w ye vc ) n ae on ct s n og r di e
Integrating with non-Scala
Spring
You can mix your existing Spring Config file into functional
configuration.
c as Pr oC ni u ai ne tn sFn to aC ni u ai n{
l s e sn of gr to xe d uc in l of gr to
ip rC as Nm C ni ua in (
mo t ls [a eo fg r to ])
vl jh = ba ( {
a on
en )
n wP ro (e B a( fr ta e) g te n "a ta e )
e es ng te n" i sN m", eB a( ls N m" )
}
}

Mixing XML...
c as Pr oC ni u ai ne tn sFn to aC ni u ai n{
l s e sn of gr to xe d uc in l of gr to
ip rX l" ls p t: cf cn i .m "
mo t m( ca sa h/ x -o fg xl)
ba ( {
en )
C fx oe [e p ee vc ]
x E ps rP ol Sr i e
}
}
4. Why use Spring Scala

Your snippets were nice, but give me a real reason to use this
library.
Rant #1

I can use pure Java Config with Scala!
@ en ii Mt o =" hs S rn h sb e r f co e b a a cd n"
B a( n te hd
ti t ig a e n ea tr d y n ci et,
d sr ye hd = " l v t tp m to n ms so om c "+
e t oM to
I oe o y e e hd a e o o uh
" n dt ci gp ol m a rn ie +
a d ee tn rb es t u tm "
" nt a o i v kn m to si f nt os cl b cs +
i s ed f no ig e hd n u ci n a la k"
" n dt ci gp ol m a cm ia in t m"
a d ee tn rb es t o pl to i e)
B oe Sr ie at v mB oe ( {
r kr e vc c ie qr k r)
vl bo e =n wB oe S ri e
a r kr
e rk re vc
bo e. dC ne t r" c: /o a hs :1 1"
rk r ad on co (t p /l cl ot 66 6)
bo e
rk r
}
..
.
j se pa es n( u u, nw Ms a er ao ( {
m Tm l t. ed qe e e e sg Ce tr )
pb i Ms ae ce tM s ae Ss in ss i n t r w J S xe to {
ul c es g r ae es g( e so e so ) ho s ME cp in
r t r s s i n c e t T x M s a e " e b s t F W ";
e u n e so . ra ee te s g( Vr oi y T!)
}
}
)

Yes, you can...
Rant #2

Spring sucks! Cake/Dagger/MacWire FTW!
OK if you start greenfield project
Cake alone won't solve your problems
you can use Cake *and* Spring Scala
how likely is that your existing project uses Spring already?
Rant #3

Using Spring in Scala is stupid.
Hi Boss, I think that all the Spring trainings,
developers experience, knowHow, patterns,
practices we follow won't be needed anymore!
Scala is the next big thing, so we want to drop
all of these. BTW Will you send my team to
Scala Days? I'm aware that our budget is tight,
but you know, we need to educate...
Rant #4

But this is yet another jar in my classpath!
I don't know how to answer this in 2014...
use Maven/Ivy/Gradle/SBT?
don't deploy over Internet and watch YouTube
delete some porns from your HDD
Rant #5

Spring Scala is not 100% type safe. Spring is not type safe.
Indeed, but Spring Scala is safer than raw Spring.
Evolve, don't be a rebel #1

make yourself a favor, introduce Scala to your legacy project
pick a slice of your existing Spring application
rewrite that slice in Scala
Evolve, don't be a rebel #2

make yourself a favor, introduce Scala to your legacy project
need to implement new enhancement request for the
customer?
write it in Scala and integrate with the existing Spring
codebase
Evolve, don't be a rebel #3

make yourself a favor, introduce Scala to your legacy project
promote micro-services approach
write your micro-service module in Scala
wire it however you want
use Spring Scala to expose your service to the shared (nonScala) application context
Evolve, don't be a rebel #4
respect human factor
not everybody has to be a hacker
some people don't feel comfortable with Monads ;)
some people will learn and adapt slower than the others
create core logic in Scala, let the others to build on it in
Java/Spring
Links
Spring Scala project at GitHub
Spring Scala project forum
Introducing Spring Scala by Arjen Poutsma
Many thanks!

More Related Content

What's hot (18)

PPTX
Representing Material Culture Online: Historic Clothing in Omeka
Arden Kirkland
 
PDF
Profiling Web Archives IIPC GA 2015
Sawood Alam
 
PDF
Security of go modules lightning talk
Deep Datta
 
PDF
Top 10 pieges php afup limoges
Damien Seguy
 
PDF
Testing Fuse Fabric with Pax Exam
Henryk Konsek
 
PDF
Testing TYPO3 Applications
André Wuttig
 
PDF
The State of PHPUnit
Edorian
 
PDF
The State of PHPUnit
Edorian
 
PPS
Bdd: Tdd and beyond the infinite
Giordano Scalzo
 
ODP
Clojure made really really simple
John Stevenson
 
PDF
Fast api
Simone Di Maulo
 
PDF
GraphQL, l'avenir du REST ?
Francois Zaninotto
 
PDF
Introduction to Ansible
Mattias Gees
 
PDF
Semantic Web & TYPO3
André Wuttig
 
PDF
Auckland Programming Algorithms and Performance Meetup about Stacks & LeetCod...
Paulo Miguel Almeida
 
PDF
PyLadies Talk: Learn to love the command line!
Blanca Mancilla
 
PPTX
What is recursion?
AnuragSrivastava272
 
PDF
Clojurescript up and running
Timo Sulg
 
Representing Material Culture Online: Historic Clothing in Omeka
Arden Kirkland
 
Profiling Web Archives IIPC GA 2015
Sawood Alam
 
Security of go modules lightning talk
Deep Datta
 
Top 10 pieges php afup limoges
Damien Seguy
 
Testing Fuse Fabric with Pax Exam
Henryk Konsek
 
Testing TYPO3 Applications
André Wuttig
 
The State of PHPUnit
Edorian
 
The State of PHPUnit
Edorian
 
Bdd: Tdd and beyond the infinite
Giordano Scalzo
 
Clojure made really really simple
John Stevenson
 
Fast api
Simone Di Maulo
 
GraphQL, l'avenir du REST ?
Francois Zaninotto
 
Introduction to Ansible
Mattias Gees
 
Semantic Web & TYPO3
André Wuttig
 
Auckland Programming Algorithms and Performance Meetup about Stacks & LeetCod...
Paulo Miguel Almeida
 
PyLadies Talk: Learn to love the command line!
Blanca Mancilla
 
What is recursion?
AnuragSrivastava272
 
Clojurescript up and running
Timo Sulg
 

Viewers also liked (20)

ODP
Ana fariña galileo galilei 3ª a
anadena
 
PDF
2011インターンシップ_09N1144_横山大城
YokoyamaD
 
PPT
งานนำเสนอบทที่7
sawitri555
 
PPT
Lynda Goldman Presentation For Expo East Sept 21 2011
Lynda819
 
PPT
Slovak Consular Services in Belfast, 7 and 8 April_2014
konzulatNYC
 
PDF
Salespresentatie
marieke1990
 
PDF
Statistical supplement june 2011 final[1]
Sammit Shukla
 
PPTX
Pdhpe ppt
MissAnji
 
PPT
Stephen W. Hawking__Fakebook
a_downs13
 
PPT
Magazine covers (1st draft & final draft)
LukaMedia
 
PPTX
Ppt el alamein
Riski W
 
PPT
business globalization
wwgreatmutha
 
PDF
Farsund digitalworkshop
Eirik Leirgulen
 
PPTX
Media Music Video Pitch
mananvekaria
 
PPT
Hughes getting in early 23.6 cp
New Zealand AIDS Foundation (NZAF)
 
PDF
Crisis Communications
MWWPR
 
PDF
Programa Curricular nivel-primaria-ebr
María Julia Bravo
 
PPTX
2011 NLDS Wild Card Champions St. Louis Cardinals
aesims
 
PDF
15º Boletín informativo fundación iter
fundacioniter
 
Ana fariña galileo galilei 3ª a
anadena
 
2011インターンシップ_09N1144_横山大城
YokoyamaD
 
งานนำเสนอบทที่7
sawitri555
 
Lynda Goldman Presentation For Expo East Sept 21 2011
Lynda819
 
Slovak Consular Services in Belfast, 7 and 8 April_2014
konzulatNYC
 
Salespresentatie
marieke1990
 
Statistical supplement june 2011 final[1]
Sammit Shukla
 
Pdhpe ppt
MissAnji
 
Stephen W. Hawking__Fakebook
a_downs13
 
Magazine covers (1st draft & final draft)
LukaMedia
 
Ppt el alamein
Riski W
 
business globalization
wwgreatmutha
 
Farsund digitalworkshop
Eirik Leirgulen
 
Media Music Video Pitch
mananvekaria
 
Hughes getting in early 23.6 cp
New Zealand AIDS Foundation (NZAF)
 
Crisis Communications
MWWPR
 
Programa Curricular nivel-primaria-ebr
María Julia Bravo
 
2011 NLDS Wild Card Champions St. Louis Cardinals
aesims
 
15º Boletín informativo fundación iter
fundacioniter
 
Ad

Similar to Spring scala - Sneaking Scala into your corporation (20)

PDF
JavaFX, because you're worth it
Thierry Wasylczenko
 
PDF
Introduction to Compiler Development
Logan Chien
 
PDF
Microservices With Spring Boot and Spring Cloud Netflix
Krzysztof Sobkowiak
 
PDF
Advanced QUnit - Front-End JavaScript Unit Testing
Lars Thorup
 
PDF
Spring Roo 2.0 Preview at Spring I/O 2016
DISID
 
PDF
Modeling avengers – open source technology mix for saving the world
Cédric Brun
 
PDF
Modeling avengers – open source technology mix for saving the world econ fr
Cédric Brun
 
PDF
Code GPU with CUDA - Identifying performance limiters
Marina Kolpakova
 
PDF
PyData Paris 2015 - Track 3.2 Serge Guelton et Pierrick Brunet
Pôle Systematic Paris-Region
 
PDF
AWS Cloud Experience CA: Democratizando la Inteligencia Artificial
Amazon Web Services LATAM
 
PDF
Apache Camel: rotas para as suas mensagens
Bruno Borges
 
PDF
Open Source Systems Performance
Brendan Gregg
 
PPT
Improving Software Reliability via Mining Software Engineering Data
Tao Xie
 
PDF
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Ajeet Singh Raina
 
PDF
機械学習エンジニアを見せたAWSの再:発明とは? 〜re:Invent 2018 参加レポート〜
cyberagent
 
PDF
Using TypeScript at Dashlane
Dashlane
 
DOCX
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
herminaprocter
 
DOCX
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
odiliagilby
 
PDF
OOP in Rust
KENZ_gelsoft
 
PDF
Kamil witecki asynchronous, yet readable, code
Kamil Witecki
 
JavaFX, because you're worth it
Thierry Wasylczenko
 
Introduction to Compiler Development
Logan Chien
 
Microservices With Spring Boot and Spring Cloud Netflix
Krzysztof Sobkowiak
 
Advanced QUnit - Front-End JavaScript Unit Testing
Lars Thorup
 
Spring Roo 2.0 Preview at Spring I/O 2016
DISID
 
Modeling avengers – open source technology mix for saving the world
Cédric Brun
 
Modeling avengers – open source technology mix for saving the world econ fr
Cédric Brun
 
Code GPU with CUDA - Identifying performance limiters
Marina Kolpakova
 
PyData Paris 2015 - Track 3.2 Serge Guelton et Pierrick Brunet
Pôle Systematic Paris-Region
 
AWS Cloud Experience CA: Democratizando la Inteligencia Artificial
Amazon Web Services LATAM
 
Apache Camel: rotas para as suas mensagens
Bruno Borges
 
Open Source Systems Performance
Brendan Gregg
 
Improving Software Reliability via Mining Software Engineering Data
Tao Xie
 
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Ajeet Singh Raina
 
機械学習エンジニアを見せたAWSの再:発明とは? 〜re:Invent 2018 参加レポート〜
cyberagent
 
Using TypeScript at Dashlane
Dashlane
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
herminaprocter
 
Y o u r N a m e L S P 2 0 0 - 3 2 0 ( c o u r s e I .docx
odiliagilby
 
OOP in Rust
KENZ_gelsoft
 
Kamil witecki asynchronous, yet readable, code
Kamil Witecki
 
Ad

More from Henryk Konsek (17)

PDF
How to cloud #1: Create Kafka cluster with Confluent Cloud
Henryk Konsek
 
PDF
Eclipse Kapua messaging refactoring proposal
Henryk Konsek
 
PDF
Containerize!
Henryk Konsek
 
PDF
Open source IoT gateway
Henryk Konsek
 
PDF
Open source IoT gateway: Tale of Eclipse Kura, Apache Camel and Rhiot
Henryk Konsek
 
PDF
Iot gateway dream team - Eclipse Kura and Apache Camel
Henryk Konsek
 
PDF
Internet Of Things for mere mortals
Henryk Konsek
 
PDF
(Ultra quick) Rhiot overview
Henryk Konsek
 
PDF
Internet Of Things for mere mortals
Henryk Konsek
 
PDF
Docker for mere mortals
Henryk Konsek
 
PDF
Iot and the back-end developers
Henryk Konsek
 
PDF
Containerize! Between Docker and Jube.
Henryk Konsek
 
PDF
IoT gateway dream team - Eclipse Kura and Apache Camel
Henryk Konsek
 
PDF
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
PDF
Fabric8 - Being devOps doesn't suck anymore
Henryk Konsek
 
PDF
Messaging with the Docker
Henryk Konsek
 
PDF
Crash course to the Apache Camel
Henryk Konsek
 
How to cloud #1: Create Kafka cluster with Confluent Cloud
Henryk Konsek
 
Eclipse Kapua messaging refactoring proposal
Henryk Konsek
 
Containerize!
Henryk Konsek
 
Open source IoT gateway
Henryk Konsek
 
Open source IoT gateway: Tale of Eclipse Kura, Apache Camel and Rhiot
Henryk Konsek
 
Iot gateway dream team - Eclipse Kura and Apache Camel
Henryk Konsek
 
Internet Of Things for mere mortals
Henryk Konsek
 
(Ultra quick) Rhiot overview
Henryk Konsek
 
Internet Of Things for mere mortals
Henryk Konsek
 
Docker for mere mortals
Henryk Konsek
 
Iot and the back-end developers
Henryk Konsek
 
Containerize! Between Docker and Jube.
Henryk Konsek
 
IoT gateway dream team - Eclipse Kura and Apache Camel
Henryk Konsek
 
Apache Camel in the belly of the Docker whale
Henryk Konsek
 
Fabric8 - Being devOps doesn't suck anymore
Henryk Konsek
 
Messaging with the Docker
Henryk Konsek
 
Crash course to the Apache Camel
Henryk Konsek
 

Recently uploaded (20)

PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Python basic programing language for automation
DanialHabibi2
 
July Patch Tuesday
Ivanti
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

Spring scala - Sneaking Scala into your corporation

  • 1. Spring Scala Sneaking Scala into your corporation Brought to you by Henryk Konsek / @hekonsek
  • 2. About me open source committer, evangelist and adopter Apache Camel Spring Scala (Spring Source aka VMware aka Pivotal) 7 years of professional experience Artegence aka Filmweb Asseco Pitney Bowes Java Black Belt freelance consulting
  • 3. About me Hired by Red Hat (JBoss) to work with JBoss Fuse stack: Apache ServiceMix Apache ActiveMQ JBoss HornetQ Apache Camel Apache CXF http://jboss.org/jbossfuse
  • 4. 1. 2. 3. 4. This talk Some context What is Spring Scala How to use Spring Scala Why use Spring Scala
  • 5. 1. Some context Inversion Of Control (IoC) Dependency Injection (DI) Spring
  • 6. Spring guide for busy developers Defining dependency to be used in application: @ of gr to C ni u ai n p bi c as Iv ie aC n iu ai n { u lc l s no c Do of gr t o @e nI vi ea i vi e a( { Ba no cD o no cD o) r tr n wI vi ea ( ; e u n e n o cD o) } @e nI vi ee v c i v ie ev c( { Ba no cS ri e no cS r ie ) r tr n wI vi ee v c( no cD o) ; e u n e n o cS ri ei v ie a( ) } }
  • 7. Spring guide for busy developers Using the dependency in the application: p bi c as Iv ie eo t ee ao { u lc l s no c Rp rG nr t r @n et Ij c pi ae Iv ie e vc i vi ee vc ; rv t n oc Sr ie n oc S ri e pb i Ls <n oc >i v ie Fr ot (n y a, i tm nh { ul c it Iv i e no cs o Mn hi t er n o t) I vi eu r qe y= I vi eu re .e rya )m nh m nh ; n o cQ ey u r n oc Q ei sy a(er . ot(o t) r tr i vi ee vc . id no cs qe y ; e u n n oc S ri ef nI v ie (u r) } }
  • 8. 2. What is Spring Scala official project from Spring Source (aka VMware, aka Pivotal) portfolio API for defining beans in Scala wrappers for existing Spring API (aka Pimp My Spring)
  • 9. 3. How to use Spring Scala
  • 10. Defining beans c as MS aa of g et ns Fn t oa Cn iu ai n { l s y cl Cn i xe d u ci nl of g rt o vl do =b a( ( ya () a a en )M Do ) ba (( ye vc ( a( ) en ) MS ri ed o) ) } define bean of type MyDao and bean of type MyService MyDao is wired into MyService
  • 11. Defining beans c as MS aa of g et ns Fn t oa Cn iu ai n { l s y cl Cn i xe d u ci nl of g rt o vl do =b a( { a a en ) M Do ) ya( } ba ( { en ) M Sr ie do ) y e vc (a () } } Notice functions!
  • 12. Defining beans - lifecycle c a s M s a e r k r o f g r t o e t n s F n t o a C n i u a i n{ l s e sg Bo eC ni u ai n xe d uc in l of gr to ba (a e= "c i eq rk r) { en n m a tv mB o e" v lb oe = nw Bo e Sr ie a rk r e r kr ev c b oe .d Cn e tr "c :/ o ah s: 11 " r k ra do nc o( t p/ lc lo t6 6 6) b oe rkr }i i { nt _ sa t) . t r( }d sr y{ eto _ so ( . t p) } } We avoid hard-coding method names. We invoke them instead.
  • 13. Accessing beans v lc ne t= Fn t oa Cn iA p ia in ot x[ y cl Cn i] a otx u ci nl o fg pl ct oC n et MS aa o fg v ls ri e= cn e tM Sr ie a evc o tx [y e vc ]
  • 14. (Globally) Accessing beans Config o jc M Sa ao fg et n sF nt oa Cn i ua in{ b et y cl Cn i x ed u c in lo fg rt o vl do =b a( ( ya () a a en )M Do ) vl sr ie =b a (( ye vc ( a( ) a e vc en )M S ri ed o) ) } + application bootstrap o jc M Ap et ns Ap { b et y p xe d p nw Fn to aC n iA pi ai n ot x( . e u ci nl of gp l ct oC ne t) r gs eC ni u ai n( yc l Cn i) e i tr of gr to s MS aa of g } = global access M S a a o f g s r i e ) m S r i e e h d) y cl C ni .e vc (. y ev cM to( Or even global access on steroids! i pr M Sa ao fg _ m ot y cl Cn i . .. . s ri e) mS ri e eh d) e vc ( .y ev cM to (
  • 15. Pimping your existing contexts v lx lo tx = nw Ca s ah mA pi ai n ot x( ca s ah ba sx l ) a m C ne t e l sP tX l pl ct oC ne t "l sp t: en . m" v ls aa ot x = a c l Cn et A pi ai no t xC ne so s tR cA pi ai n ot x( mC ne t p l ct oC ne to v ri n. oi hp l ct oC ne t xl ot x) v ls ri e= sa a ot x[ ye v c] a evc c lC ne t MS ri e For those who aren't easily frightened by implicit conversions: i pr o gs rn fa eo k sa ac ne t A p ia in ot x Cn es os _ m ot r .p ig r mw r. cl . ot x. pl ct o Cn et ov ri n. v lx lo tx = nw Ca s ah mA pi ai n ot x(ca s ah ba sx l ) a m C ne t e l sP tX l pl ct oC ne t"l sp t: en . m" v ls ri e= xl o tx [y ev c ] a evc m Cn et M Sr ie
  • 16. Scala friendly API #1 JmsTemplate v lc ne to Fc o y: Cn et o Fc oy = .. a o n ci na tr o nc in at r . v lt ml t =n wJ se p ae cn et oF c oy a e p ae e mT ml t( o nc in at r) Function callbacks instead of anonymous inner functions. t ml t. ed"u u" {s si n Ss in = e pa e sn(q ee) e so : es o > ss in ce tT x Ms ae "e l Wr d ) es o .r ae et es g (H lo o l" } Pattern matching friendly return types. t ml t. ee v( q ee )m th { e pa e rc ie "u u" ac cs S m( :T xM sa e = pi tn mg t et ae o em e t es g) > r nl (. eT x) cs N n = p it n" o tx m sa er ci e" ae o e > r n l( N et e sg e e vd) }
  • 17. Scala friendly API #2 JdbcTemplate v lt ml t =n wJ bT m lt (a ao re a e p ae e dc ep ae d tS uc ) Functions instead of callbacks v lt ml t. ur A da(S LC l gn FO U E" { a e p ae qe yn Mp " EE T oi R M SR ) (e ut e, rw u )= rs l St o Nm > " d %"fr a (o Nm r sl St gt t ig 1) %: s.o mt rw u , e u te .e Sr n () } Scala collections instead of java.util API v lu es :M pS r n, nR f =t ml t. u rF ra (S L C * FO U E" a sr a[ ti gA y e] ep ae qe yo M p" EE T R M SR ) Options instead of nulls v lq ey =" EE T lg nF O UE W EE i =? a ur SL C oi RM S R H R d " v ll gn =t ml t .u rF rb e tS rn ]q ey , 1 m t h{ a oi ep ae qe y oO jc [t ig ( ur ) ac Sm (o i) oe l gn Nn = "e al L gn oe > d fu to i" }
  • 18. Scala friendly API #3 Aspect Oriented Programming Defining aspects as (anonymous inner) classes is overkill. v ll ge Av c = a o g rd ie (e hd M to ,a g: A ry Ay e] t re :A y = mt o : e hd rs r a[ n Rf , a g t n) > l gd bg "x c tn m to { " m to . eN m) o . eu (E eu ig e hd } , eh dg ta e v ls vP it u =( :M t o, c Ca s_ )= m gt ae s at Wt (s v" a a e on ct m eh d : ls [] > . e Nm .t rs ih " ae ) What about wiring aspects into beans? a vc t re (e M Sr i e o s vP it u ui g lg eA vc d ie a gt n w ye vc ) n ae on ct s n og r di e
  • 19. Integrating with non-Scala Spring You can mix your existing Spring Config file into functional configuration. c as Pr oC ni u ai ne tn sFn to aC ni u ai n{ l s e sn of gr to xe d uc in l of gr to ip rC as Nm C ni ua in ( mo t ls [a eo fg r to ]) vl jh = ba ( { a on en ) n wP ro (e B a( fr ta e) g te n "a ta e ) e es ng te n" i sN m", eB a( ls N m" ) } } Mixing XML... c as Pr oC ni u ai ne tn sFn to aC ni u ai n{ l s e sn of gr to xe d uc in l of gr to ip rX l" ls p t: cf cn i .m " mo t m( ca sa h/ x -o fg xl) ba ( { en ) C fx oe [e p ee vc ] x E ps rP ol Sr i e } }
  • 20. 4. Why use Spring Scala Your snippets were nice, but give me a real reason to use this library.
  • 21. Rant #1 I can use pure Java Config with Scala! @ en ii Mt o =" hs S rn h sb e r f co e b a a cd n" B a( n te hd ti t ig a e n ea tr d y n ci et, d sr ye hd = " l v t tp m to n ms so om c "+ e t oM to I oe o y e e hd a e o o uh " n dt ci gp ol m a rn ie + a d ee tn rb es t u tm " " nt a o i v kn m to si f nt os cl b cs + i s ed f no ig e hd n u ci n a la k" " n dt ci gp ol m a cm ia in t m" a d ee tn rb es t o pl to i e) B oe Sr ie at v mB oe ( { r kr e vc c ie qr k r) vl bo e =n wB oe S ri e a r kr e rk re vc bo e. dC ne t r" c: /o a hs :1 1" rk r ad on co (t p /l cl ot 66 6) bo e rk r } .. . j se pa es n( u u, nw Ms a er ao ( { m Tm l t. ed qe e e e sg Ce tr ) pb i Ms ae ce tM s ae Ss in ss i n t r w J S xe to { ul c es g r ae es g( e so e so ) ho s ME cp in r t r s s i n c e t T x M s a e " e b s t F W "; e u n e so . ra ee te s g( Vr oi y T!) } } ) Yes, you can...
  • 22. Rant #2 Spring sucks! Cake/Dagger/MacWire FTW! OK if you start greenfield project Cake alone won't solve your problems you can use Cake *and* Spring Scala how likely is that your existing project uses Spring already?
  • 23. Rant #3 Using Spring in Scala is stupid. Hi Boss, I think that all the Spring trainings, developers experience, knowHow, patterns, practices we follow won't be needed anymore! Scala is the next big thing, so we want to drop all of these. BTW Will you send my team to Scala Days? I'm aware that our budget is tight, but you know, we need to educate...
  • 24. Rant #4 But this is yet another jar in my classpath! I don't know how to answer this in 2014... use Maven/Ivy/Gradle/SBT? don't deploy over Internet and watch YouTube delete some porns from your HDD
  • 25. Rant #5 Spring Scala is not 100% type safe. Spring is not type safe. Indeed, but Spring Scala is safer than raw Spring.
  • 26. Evolve, don't be a rebel #1 make yourself a favor, introduce Scala to your legacy project pick a slice of your existing Spring application rewrite that slice in Scala
  • 27. Evolve, don't be a rebel #2 make yourself a favor, introduce Scala to your legacy project need to implement new enhancement request for the customer? write it in Scala and integrate with the existing Spring codebase
  • 28. Evolve, don't be a rebel #3 make yourself a favor, introduce Scala to your legacy project promote micro-services approach write your micro-service module in Scala wire it however you want use Spring Scala to expose your service to the shared (nonScala) application context
  • 29. Evolve, don't be a rebel #4 respect human factor not everybody has to be a hacker some people don't feel comfortable with Monads ;) some people will learn and adapt slower than the others create core logic in Scala, let the others to build on it in Java/Spring
  • 30. Links Spring Scala project at GitHub Spring Scala project forum Introducing Spring Scala by Arjen Poutsma