There are many properties that need to be set in the Akka application, either programmatically or via configuration. Configuration is the recommended approach to set the properties in the Akka application.
To step through this recipe, we just need to import the Hello-Akka
project; other prerequisites are the same as earlier. By default, configuration is read from application.conf, but it can be read from any .conf
file. Usually, we put all conf files in the project resources folder.
- Create a conf file, say,
akka.conf
, in the project'ssrc/main/resources
folder.
- For example, add the following properties to
akka.conf
:
myactor { actorname=actor1 actorsystem=hell-akka }
- Create an
ActorWithConfig.scala
file in thecom.packt.chapter5
package. - Add the following import to the top of the file:
import akka.actor.{Props, Actor, ActorSystem} import com.typesafe.config.Config import com.typesafe...