No configuration setting found for key 'akka.version'

匿名 (未验证) 提交于 2018-03-17 14:53:49

问题:

I am learning akka-remoting and this is how my project looks

The project structure looks like

project/pom.xml
project/mymodule/pom.xml
project/mymodule/src/main/resources/application.conf
project/mymodule/src/main/scala/com.harit.akkaio.remote.RemoteApp.scala
project/mymodule/src/main/scala/com.harit.akkaio.remote.ProcessingActor.scala

When I run my project on command-line, I see

$ java -jar akkaio-remote/target/akka-remote-jar-with-dependencies.jar com.harit.akkaio.remote.RemoteApp
Hello:com.harit.akkaio.remote.RemoteApp
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:145)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206)
    at akka.actor.ActorSystem$Settings.(ActorSystem.scala:169)
    at akka.actor.ActorSystemImpl.(ActorSystem.scala:505)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:142)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:119)
    at com.harit.akkaio.remote.RemoteApp$.startProcessingActorSystem(RemoteApp.scala:16)
    at com.harit.akkaio.remote.RemoteApp$.main(RemoteApp.scala:12)
    at com.harit.akkaio.remote.RemoteApp.main(RemoteApp.scala)

RemoteApp.scala

package com.harit.akkaio.remote

import akka.actor.{ActorRef, ActorSystem, Props}
import com.typesafe.config.ConfigFactory

import scala.concurrent.duration._

object RemoteApp {
  def main(args: Array[String]): Unit = {
    println("Hello:" + args.head)
      startProcessingActorSystem()
  }

  def startProcessingActorSystem() = {
    val system = ActorSystem("ProcessingSystem", ConfigFactory.load())
    println("ProcessingActorSystem Started")
  }
}

ProcessingActor.scala

package com.harit.akkaio.remote

import akka.actor.{Actor, ActorLogging}

case object Process

case object Crash

class ProcessingActor extends Actor with ActorLogging {
  def receive = {
    case Process => log.info("processing big things")
    case Crash => log.info("crashing the system")
      context.stop(self)
  }
}

application.conf

akka {
  remote.netty.tcp.port = 2552
}

mymodule.pom.xml

akkaiocom.harit1.0-SNAPSHOT4.0.0akkaio-remote2.3.11com.typesafe.akkaakka-remote_2.11${akka-remote_2.11.version}maven-assembly-pluginakka-remotecom.harit.akkaio.remote.RemoteAppjar-with-dependenciesmake-assemblypackagesingle

pom.xml

4.0.0com.haritakkaio1.0-SNAPSHOTakkaio-remotepom20152.11.64.122.2.52.3.112.3.112.3.111.10.192.11.61.0scala-tools.orgScala-Tools Maven2 Repositoryhttp://scala-tools.org/repo-releasesscala-tools.orgScala-Tools Maven2 Repositoryhttp://scala-tools.org/repo-releasesorg.scala-langscala-library${scala.version}com.typesafe.akkaakka-actor_2.11${akka-actor_2.11.version}com.typesafe.akkaakka-slf4j_2.11${akka-slf4j_2.11.version}org.scalatestscalatest-maven-plugin${scalatest-maven-plugin.version}compilecom.typesafe.akkaakka-testkit_2.11${akka-testkit_2.11.version}testorg.scalatestscalatest_2.11${scalatest_2.11.version}testclean installorg.scala-toolsmaven-scala-plugincompiletestCompile${maven-scala-plugin.scalaCompatVersion}${scala.version}${scala.version}-target:jvm-1.8org.apache.maven.pluginsmaven-surefire-plugin2.7trueorg.scalatestscalatest-maven-plugin1.0${project.build.directory}/surefire-reports.WDF TestSuite.txttesttestorg.scala-toolsmaven-scala-plugin${scala.version}

What am I missing out? Thanks

回答1:

It seems that your problem is bundling into a jar-with-dependencies, which causes problems with Akka, as described in the documentation:

Warning

Akka's configuration approach relies heavily on the notion of every module/jar having its own reference.conf file, all of these will be discovered by the configuration and loaded. Unfortunately this also means that if you put/merge multiple jars into the same jar, you need to merge all the reference.confs as well. Otherwise all defaults will be lost and Akka will not function.

As suggested on the same page, you can use maven-shade-plugin to merge all the reference configurations:

If you are using Maven to package your application, you can also make use of the Apache Maven Shade Plugin support for Resource Transformers to merge all the reference.confs on the build classpath into one.

See also: Akka: missing akka.version



回答2:

Had a simular issue:

com.typesafe.config.ConfigException$Missing: 
No configuration setting found for key 'akka.persistence.journal-plugin-fallback'

Solved it with adding an appending transformer:

maven-shade-plugin2.4.1packageshadereference.conf


回答3:

Adding AppendingTransformer alone didn't resolve the issue for me. If you are trying to deploy your spark application on EMR and are still facing this issue then please take a look at my solution here. Hope it helps!