Search code examples
javaakkaactorproperties-filehocon

AKKA .conf file configuration to .properties file


In my test.conf file I have the following configuration

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"

    serializers {
       java = "akka.serialization.JavaSerializer"
    }

    serialization-bindings {
        "java.io.Serializable" = "kyro"
    }
  }
}

I am trying to put this configuation in test.properties file as

akka.actor.provider=akka.cluster.ClusterActorRefProvider
akka.actor.serializers.java=akka.serialization.JavaSerializer
akka.actor.serialization-bindings."java.io.Serializable" = kryo

When I create and AKKA ActorSystem using test.conf file it is working fine but when I am creating an ActorSytem with the test.propeties file as

System.setProperty("config.file", "test.properties");
Config config = ConfigFactory.load();
ActorSystem testactor = ActorSystem.create("testactor", config);

Here I am getting java ClassNotFoundExcpetion : "java

I seens the way I put the akka.actor.serialization-bindings."java.io.Serializable" in test.properties file is not correct.Please suggest the correct way to put this in .properties file.


Solution

  • I understood you want a properties file though I don't think you can declare a key in this way and also remember you have a powerful configuration tool in your hands.

    I'd suggest to put all your default application configuration in reference.conf and override using application.conf hence you can just drop a specific application.conf on your classpath for testing on test/resources.

    This could be your java/resources/reference.conf:

    akka {
     actor {
      provider = "akka.cluster.ClusterActorRefProvider"
    
       serializers {
        java = "akka.serialization.JavaSerializer"
       }
    
      serialization-bindings {
       "java.io.Serializable" = "kyro"
      }
     }
    }
    

    And you put this on test/resources/application.conf or whatever you need for testing:

    akka {
      serialization-bindings {
       "java.io.Serializable" = "java"
      }
    } 
    

    When you call ConfigFactory.load() all files will be merged in one configuration.

    I advise to read more about how to configure and override the configuration: http://doc.akka.io/docs/akka/current/general/configuration.html#Configuring_multiple_ActorSystem