Spring Scala
Arjen Poutsma
Ramnivas Laddad
Pivotal
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without pe...
About Arjen
• Twenty years of experience in Enterprise Software
Development
• Joined SpringSource in 2005
• Development le...
Why Spring and Scala?
• Scala has many exciting features
–Pattern matching, implicits, functions, JVM, ...

• Spring is th...
Introducing Spring Scala
• Separate Spring portfolio project
• Introduced at last year’s SpringOne 2GX
• Goal: make it eas...
Spring Scala Features
• Wiring up Scala Beans in XML
–Support for Scala Collections

• Wiring up Scala Beans in Scala
• Sc...
Wiring up in XML
• Constructor injection, or
• @BeanProperty, or
• Spring Scala & Spring 3.2+

6
Properties in Scala
class	
  A(var	
  b:	
  String)
public	
  class	
  A	
  {
private	
  String	
  b;
public	
  A(String	
...
Demo

8
Scala Collections
• Rich API
• Seq, IndexedSeq, LinearSeq, Buffer, Set, Map, etc.
• Mutable and Immutable version
• Spring...
Demo

10
Wiring up in Scala
• FunctionalConfiguration (aka ScalaConfig)
• Singletons and prototypes
• Bean references
• Configurati...
<beans>
	
  	
  	
  	
  <bean	
  class="Person">
	
  	
  	
  	
  	
  	
  	
  	
  <constructor-­‐arg	
  value="John"/>
	
  ...
Demo

13
Spring Templates
• Consistent and convenient approach to data access
–JdbcTemplate, JmsTemplate, ...

• Spring Scala has S...
JmsTemplate
val	
  connectionFactory	
  :	
  ConnectionFactory	
  =	
  ...
val	
  template	
  =	
  new	
  JmsTemplate(conn...
Demo

16
Further information
• Github repo opened October 2012
• First milestone released December 2012
• Second milestone released...
Upcoming SlideShare
Loading in …5
×

Spring Scala

759 views

Published on

Speakers: Ramnivas Laddad and Arjen Poutsma
The Spring Framework is one of the most popular Java frameworks used today. While it is possible to use Spring in Scala, it does feel awkward in certain places, because of the "Javaism" peering through. For instance, using callback interfaces feels strange in Scala; functions would be a better match.
At SpringOne 2GX last year, I introduced the Spring Scala project, which solves this particular issue, and aims to make it easier to use Spring in Scala in general. In this session, we discuss the Spring Scala portfolio project and its feature set.
We will also show a real-world application that combines robustness and maturity of the Spring Framework with coolness of Scala. It features a REST-based architecture with on Spring and Scala backend and AngularJS frontend to offer a modern, single-page experience.

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
759
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Spring Scala

  1. 1. Spring Scala Arjen Poutsma Ramnivas Laddad Pivotal © 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
  2. 2. About Arjen • Twenty years of experience in Enterprise Software Development • Joined SpringSource in 2005 • Development lead of Spring Web Services • Development lead on Spring 3’s REST support • Dabbled in Scala in 2008 2
  3. 3. Why Spring and Scala? • Scala has many exciting features –Pattern matching, implicits, functions, JVM, ... • Spring is the de facto Java Enterprise framework –more than DI, proven, 10+ development years, ... • Why not combine them? 3
  4. 4. Introducing Spring Scala • Separate Spring portfolio project • Introduced at last year’s SpringOne 2GX • Goal: make it easier to use Spring in Scala • Built on top of the Spring Java Framework 4
  5. 5. Spring Scala Features • Wiring up Scala Beans in XML –Support for Scala Collections • Wiring up Scala Beans in Scala • Scala-friendly versions of Spring Templates 5
  6. 6. Wiring up in XML • Constructor injection, or • @BeanProperty, or • Spring Scala & Spring 3.2+ 6
  7. 7. Properties in Scala class  A(var  b:  String) public  class  A  { private  String  b; public  A(String  b)  { this.b  =  b; } public  String  b()  { return  b; } public  void  b_$eq(String  b)  { this.b  =  b; } } 7
  8. 8. Demo 8
  9. 9. Scala Collections • Rich API • Seq, IndexedSeq, LinearSeq, Buffer, Set, Map, etc. • Mutable and Immutable version • Spring Scala supports all of these –PropertyEditors –XML namespace 9
  10. 10. Demo 10
  11. 11. Wiring up in Scala • FunctionalConfiguration (aka ScalaConfig) • Singletons and prototypes • Bean references • Configuration Composition • Importing XML and @Configuration • Init and destroy methods • Bean Profiles 11
  12. 12. <beans>        <bean  class="Person">                <constructor-­‐arg  value="John"/>                <constructor-­‐arg  value="Doe"/>        </bean> </beans> class  PersonConfiguration    extends  FunctionalConfiguration  {        bean()  {                new  Person("John",  "Doe")        } } 12
  13. 13. Demo 13
  14. 14. Spring Templates • Consistent and convenient approach to data access –JdbcTemplate, JmsTemplate, ... • Spring Scala has Scala versions of these: –Functions instead of callbacks –Option 14
  15. 15. JmsTemplate val  connectionFactory  :  ConnectionFactory  =  ... val  template  =  new  JmsTemplate(connectionFactory) template.send("queue")  {        session:  Session  =>  session.            createTextMessage("Hello  World") } template.receive("queue")  match  {        case  Some(m:  TextMessage)=>  println(m.getText)        case  None  =>  println("No  text  message  received") } 15
  16. 16. Demo 16
  17. 17. Further information • Github repo opened October 2012 • First milestone released December 2012 • Second milestone released April 2013 • First release candidate release September 2013 • 1.0 GA “soon” • Community-driven https://github.com/SpringSource/spring-scala 17

×