Question

I'm trying to set up a basic Spray Can server. In the code, I see this:

IO(Http) ! Http.Bind(service, interface = "localhost", port = 8080)

I'd like to have that port (8080) be configured from the application.conf file. However, the format of the conf file (http://spray.io/documentation/1.2-M8/spray-can/configuration/) does not have a port defined.

Does this mean the way to accomplish this is to define a port configuration myself, and read it from application.conf? And if so, how is this done?

Was it helpful?

Solution

You'll need to add a port setting to application.conf and load it manually, like this.

import com.typesafe.config._
val conf = ConfigFactory.load()
val serverPort = conf.getInt("port")
IO(Http) ! Http.Bind(service, interface = "localhost", port = serverPort)

where src/main/resources/application.conf looks like this:

port = 8090
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top