Reputation: 19438
I am creating custom configurations for my akka application written in java as follows
application.conf
akka {
actor {
debug {
# enable DEBUG logging of actor lifecycle changes
lifecycle = on
}
}
}
I am not sure how to load this configuration. It is unclear from the docs if this needs to be explicitly loaded at actrSystem creation or if it needs to be in the class path while running the jar. In both cases, is there an example I can look at
This is a maven project and the configuration file is under src/main/resources
I see that the applucation.conf exists under target/classes. Is that it?
Upvotes: 3
Views: 5080
Reputation: 498
With ConfigFactory you can load the application.conf file from src/main/resources, not necessarily need an ActorSystem to use it
According to the akka doc http://doc.akka.io/docs/akka/2.4/general/configuration.html
A simple test
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
public class ConfigFactoryTest {
public static void main(String[] args) {
Config conf = ConfigFactory.load("application.conf");
System.out.println(conf.getString("akka.actor.debug.lifecycle")); //should be 'on'
}
}
Also can use withFallback
method
http://doc.akka.io/docs/akka/2.4/general/configuration.html#Reading_configuration_from_a_custom_location
Assume you have another properties file called fallback.conf
akka {
actor {
fallback = "fallback"
}
}
Config fallback = ConfigFactory.load("fallback.conf")
Config conf = ConfigFactory.load("application.conf").withFallback(fallback);
System.out.println(conf.getString("akka.actor.fallback")); //fallback
Here you can find examples :
https://github.com/typesafehub/config/tree/master/examples/java
Upvotes: 4