spring scala

17
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Spring Scala Arjen Poutsma Ramnivas Laddad Pivotal

Upload: spring-io

Post on 01-Nov-2014

593 views

Category:

Technology


2 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Spring Scala

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Spring ScalaArjen Poutsma

Ramnivas LaddadPivotal

Page 2: Spring Scala

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

Page 3: Spring Scala

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

Page 4: Spring Scala

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

Page 5: Spring Scala

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

Page 6: Spring Scala

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

6

Page 7: Spring Scala

Properties in Scala

7

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;

}}

Page 8: Spring Scala

Demo

8

Page 9: Spring Scala

Scala Collections

9

• Rich API• Seq, IndexedSeq, LinearSeq, Buffer, Set, Map, etc.• Mutable and Immutable version• Spring Scala supports all of these

–PropertyEditors–XML namespace

Page 10: Spring Scala

Demo

10

Page 11: Spring Scala

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

Page 12: Spring Scala

12

<beans>        <bean  class="Person">                <constructor-­‐arg  value="John"/>                <constructor-­‐arg  value="Doe"/>        </bean></beans>

class  PersonConfiguration    extends  FunctionalConfiguration  {        bean()  {                new  Person("John",  "Doe")        }}

Page 13: Spring Scala

Demo

13

Page 14: Spring Scala

Spring Templates

14

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

• Spring Scala has Scala versions of these:–Functions instead of callbacks–Option

Page 15: Spring Scala

15

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")}

JmsTemplate

Page 16: Spring Scala

Demo

16

Page 17: Spring Scala

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