0

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.

Rohit Thakur
  • 244
  • 2
  • 12

2 Answers2

-1

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

Leo
  • 1,102
  • 2
  • 11
  • 18
  • I want to maintain only one configuration file either my test.conf or test.properties and not the both.In case of test.properties I need to know how to put serialization-bindings property.If this is not possible in .properties file I have to go with test.conf file – Rohit Thakur Apr 21 '17 at 09:50
  • I am afraid you're out of option in this case. Stick with the hocon format. – Leo Apr 21 '17 at 12:10
  • Overriding default Akka config (the `akka` namespace) must not be done using a `reference.conf` as it will depend on class path ordering if those settings are ever seen. – johanandren Apr 26 '17 at 06:52
-1

The Typesafe config library allows for loading properties objects and combining configs so you could do:

// or load it from a file using whatever logic you want
Properties properties = new Properties();
properties.setProperty("some.setting", "a-value");

Config propConfig = ConfigFactory.parseProperties(properties);
Config actualConfig = propConfig.withFallback(ConfigFactory.load("test.conf"));
ActorSystem.create("name", actualConfig);

Update: as Leo pointed out in a comment, if you want to override akka.actor.serialization-bindings."java.io.‌​Serializable" that is indeed not possible with Properties as far as I can see because of the quotes.

johanandren
  • 11,249
  • 1
  • 25
  • 30
  • This is not an option. He wants to override `akka.actor.serialization-bindings."java.io.Serializable"`. Properties keys can't have quotes afaik. – Leo Apr 26 '17 at 14:31
  • 1
    Sure they can: `properties.put("akka.actor.serialization-bindings.\"java.io.Serializable\"", "someval")` works fine. However there is a problem in that the Typesafe Config library does not treat quotes specially when parsing properties, it will interpret the dots in the full class name as sub-namespaces and it therefore does indeed not work for the given use case. – johanandren Apr 27 '17 at 12:33
  • You're right, however I prefer a clean approach and embrace HOCON altogether. My 2c. – Leo Apr 27 '17 at 13:34