How to load application.conf in Akka

1.8k Views Asked by At

can anyone help me with the following question. I am using play frame work and Akka. My programming language is Java. I am trying to use Akka Cluster. In Akka doc, it is said that the application.conf shall be put in src/main/resources. However in Play frame work, there is no folder named src. So I have to create the folder src and put the application.conf there. Also I put my code in src/main/java/sample/cluster/simple. But it seems the application.conf cannot be loaded in the ActorSystem. I tried

System.out.println(system.settings());

But I did not see any changes of the configuration. If I put all the configuration details in

Config config = ConfigFactory.parseString("...")

It works very well. Does anyone know what is worn here? Thank you very much.

1

There are 1 best solutions below

0
On

In Play, application.conf is traditionally kept in the conf directory. It's not clear from your question whether you're using a Play project or a vanilla SBT project. Ultimately, the location of the config file will come down to what you've defined as your resources directory. From your SBT console, you can do show unmanagedResources to get a list of these locations and the files currently loaded as resources.

In Play, you can access the current config through play.api.Play.current.configuration. In Akka, you can use myActorSystem.settings.configuration. Or, within an actor: context.system.settings.configuration.

Note that both Play and Akka use Typesafe's config library for parsing config files. It's quite powerful but you don't need to know all the details to get started.