找不到密钥'akka.version'的配置设置

时间:2015-06-23 18:59:23

标签: scala maven akka typesafe-stack typesafe-config

我正在学习akka-remoting,这就是我的项目的样子

项目结构类似于

Seq

当我在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 上运行我的项目时,我看到了

command-line

RemoteApp.scala

$ 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.<init>(ActorSystem.scala:169)
    at akka.actor.ActorSystemImpl.<init>(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)

ProcessingActor.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")
  }
}

application.conf

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)
  }
}

mymodule.pom.xml

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

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>akkaio</artifactId>
        <groupId>com.harit</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>akkaio-remote</artifactId>

    <properties>
        <akka-remote_2.11.version>2.3.11</akka-remote_2.11.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-remote_2.11</artifactId>
            <version>${akka-remote_2.11.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <finalName>akka-remote</finalName>
                    <archive>
                        <manifest>
                            <mainClass>com.harit.akkaio.remote.RemoteApp</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我错过了什么? 感谢

6 个答案:

答案 0 :(得分:29)

有一个类似的问题:

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

通过添加附加变压器来解决它:

<plugin>
  <artifactId>maven-shade-plugin</artifactId>
  <version>2.4.1</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>shade</goal>
      </goals>
      <configuration>
        <transformers>
          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
            <resource>reference.conf</resource>
          </transformer>
        </transformers>
      </configuration>
    </execution>
  </executions>
</plugin>

答案 1 :(得分:28)

似乎您的问题正在捆绑到jar-with-dependencies,这会导致Akka出现问题,如documentation中所述:

  

警告

     

Akka的配置方法在很大程度上依赖于每个具有自己的reference.conf文件的模块/ jar的概念,所有这些都将由配置发现并加载。不幸的是,这也意味着如果你将多个jar放入/合并到同一个jar中,你需要合并所有的reference.confs。否则所有默认值都将丢失,Akka将无法正常运行。

根据同一页面上的建议,您可以使用maven-shade-plugin合并所有参考配置:

  

如果您使用Maven打包应用程序,您还可以使用Apache Maven Shade Plugin对Resource Transformers的支持将构建类路径上的所有reference.conf合并为一个。

另请参阅:Akka: missing akka.version

答案 2 :(得分:1)

单独添加AppendingTransformer并没有为我解决问题。 如果您尝试在EMR上部署spark应用程序并且仍然面临此问题,那么请查看我的解决方案here。希望它有所帮助!

答案 3 :(得分:1)

因此,在制作胖罐子时出现问题,但没有正确处理 reference.conf

解释来自@Zoltan的答案:

看来,您的问题正捆绑在具有依赖项的jar中,这会导致Akka出现问题,如文档中所述:

警告

Akka的配置方法在很大程度上依赖于每个概念 具有自己的reference.conf文件的模块/ jar,所有这些都将是 通过配置发现并加载。不幸的是,这也 意味着如果您将多个罐子合并/合并到同一个罐子中,则需要 合并所有reference.confs。否则,所有默认设置 丢失,Akka将无法运行。

我有一个不需要插件的SBT用户解决方案。

在build.sbt中,将 case "reference.conf" => MergeStrategy.concat 添加到模块组装配置中。

lazy val module_name = (project in file("module_path"))
  .settings(
    name := "module_name",
    commonSettings,
    assemblyJarName in assembly := "module_name.jar",
    test in assembly := {},
    assemblyMergeStrategy in assembly := {
      case PathList("META-INF", xs @ _*) => MergeStrategy.discard

    #################### The line which needs to be added ###################
      case "reference.conf" => MergeStrategy.concat
      case _ => MergeStrategy.first
    }
  )
  .dependsOn(other_modules, other_modules2)

命令MergeStrategy.concat实际上以相同的方式起作用。每次遇到reference.conf进行组装时,它都会将其串联在一起,而不是为每个akka模块创建一个单独的文件(这是默认行为)。

请具有使用maven(pom.xml)的经验的人!扩展这个答案。

答案 4 :(得分:1)

添加以下插件:

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-shade-plugin</artifactId>
 <version>1.5</version>
 <executions>
  <execution>
   <phase>package</phase>
   <goals>
    <goal>shade</goal>
   </goals>
   <configuration>
    <shadedArtifactAttached>true</shadedArtifactAttached>
    <shadedClassifierName>allinone</shadedClassifierName>
    <artifactSet>
     <includes>
      <include>*:*</include>
     </includes>
    </artifactSet>
    <transformers>
      <transformer
       implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
       <resource>reference.conf</resource>
      </transformer>
      <transformer
       implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
       <manifestEntries>
        <Main-Class>akka.Main</Main-Class>
       </manifestEntries>
      </transformer>
    </transformers>
   </configuration>
  </execution>
 </executions>
</plugin>

这里参考:akka—docs enter link description here

答案 5 :(得分:0)

我尝试了这个插件,它很棒,但是由于一些签名的jar导致了另一个错误。这是错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

我建议您使用的是spring boot maven插件。只需将其添加到您的构建中,即可享受无缝的可运行罐子。这是我喜欢Spring框架的一个很好的理由。

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
            <configuration>
                <classifier>final</classifier>
                <mainClass>
                    com.main.PopularHashTags
                </mainClass>
            </configuration>
        </execution>
    </executions>
</plugin>

注意:您不需要使用Spring Boot应用程序即可使用此插件。只需在任何应用程序中使用它,它就可以发挥魅力。