Saturday, 7 September 2013

Type conversion issues in Scala when trying to work with typesafe config

Type conversion issues in Scala when trying to work with typesafe config

I am not entirely sure how to correct this issue here. I am retrieving a
List of servers using typesafe config using getStringList. I am then
attempting to instantiate a new list of ServerAddress instances. Here's
the code with the error output:
import com.mongodb.casbah.Imports._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
import com.myapp.api.models._
import com.myapp.api.init.{Settings}
import org.slf4j.{Logger, LoggerFactory}
import scala.collection.JavaConversions._
def mongoDb = {
val servers = Settings.getList("mongodb.servers")
val addresses = servers.map { new ServerAddress(_, 27017) }
val mongoConn = MongoConnection(addresses)
val db = mongoConn(Settings.getString("mongodb.database"))
db
}
Here's where the issue occurs:
[error] /vagrant/src/main/scala/com/myapp/api/dao/DAO.scala:19: overloaded
method value apply with alternatives:
[error] (host: String)com.mongodb.casbah.MongoConnection <and>
[error] (addr:
com.mongodb.ServerAddress)com.mongodb.casbah.MongoConnection <and>
[error] (uri: com.mongodb.MongoURI)com.mongodb.casbah.MongoConnection <and>
[error] (uri:
com.mongodb.casbah.MongoURI)com.mongodb.casbah.MongoConnection <and>
[error] (replicaSetSeeds:
List[com.mongodb.ServerAddress])com.mongodb.casbah.MongoConnection
[error] cannot be applied to
(scala.collection.mutable.Buffer[com.mongodb.ServerAddress])
[error] val mongoConn = MongoConnection(addresses)
[error] ^
[error] one error found
The Settings class is very straight forward:
package com.myapp.api.init
import com.typesafe.config._
object Settings {
val app = ConfigFactory.load()
def getString(key: String) = app.getString(key)
def getList(key: String) = app.getStringList(key)
def getInt(key: String) = app.getInt(key)
}
If I hardcode addresses with the following, it works fine:
val addresses = List(new ServerAddress("10.1.1.2" , 27017), new
ServerAddress("10.1.1.3" , 27017), new ServerAddress("10.1.1.4" , 27017))

No comments:

Post a Comment