Here’s how I ended up implementing it. I decided to create a singleton Scala object called dbConnector which creates and maintains the connection pool. dbConnector provides an interface for other classes to request a connection and then return it when completed: getConnection and close
I also added a testConnection method which is called when the connection pool is established. This will produce a nice output that shows a successful DB connection.
Here’s how it looks in Scala:
How it’s used by other classes:
And how’s it’s implemented in my Scalatra app (runs at app startup)
In ScalatraBootstrap.scala