spring framework

How to use the Spring Framework in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 17.4, “How to use the Spring Framework in Scala.”

Problem

You want to use the Java Spring Framework library in your Scala application.

Solution

In my experience, the only real changes in using the Spring Framework in Scala applications involve how you cast the objects you instantiate from your Spring application context file, and that’s only because the casting process is different between Scala and Java.

Scala: How to connect to a SQL database with the Spring Framework

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.2, “How to connect to a database with the Spring Framework.”

Problem

You want to connect to a database using the Spring Framework. This gives you a nice way to add connection pooling and other capabilities to your SQL code.

A Scala Spring Framework dependency injection example

Curious about how well Scala would play with the Spring Framework, I created a small Scala/Spring dependency injection example project, which I'm sharing here.

The short answer is that Scala worked just fine with Spring, but it also showed me that I still have plenty to learn about inheritance in Scala.

My Spring applicationContext.xml file

I copied a Spring applicationContext.xml file from another project, then whittled it down to these bare essentials: