【问题标题】:No configuration setting found for key 'akka.version'未找到密钥“akka.version”的配置设置
【发布时间】:2015-09-09 18:02:27
【问题描述】:

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

项目结构看起来像

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

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

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

<?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>

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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.harit</groupId>
    <artifactId>akkaio</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>akkaio-remote</module>
    </modules>

    <packaging>pom</packaging>
    <inceptionYear>2015</inceptionYear>
    <properties>
        <scala.version>2.11.6</scala.version>
        <junit.version>4.12</junit.version>
        <scalatest_2.11.version>2.2.5</scalatest_2.11.version>
        <akka-actor_2.11.version>2.3.11</akka-actor_2.11.version>
        <akka-slf4j_2.11.version>2.3.11</akka-slf4j_2.11.version>
        <akka-testkit_2.11.version>2.3.11</akka-testkit_2.11.version>
        <mockito-all.version>1.10.19</mockito-all.version>
        <maven-scala-plugin.scalaCompatVersion>2.11.6</maven-scala-plugin.scalaCompatVersion>
        <scalatest-maven-plugin.version>1.0</scalatest-maven-plugin.version>
    </properties>

    <repositories>
        <repository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>scala-tools.org</id>
            <name>Scala-Tools Maven2 Repository</name>
            <url>http://scala-tools.org/repo-releases</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.11</artifactId>
            <version>${akka-actor_2.11.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-slf4j_2.11</artifactId>
            <version>${akka-slf4j_2.11.version}</version>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest-maven-plugin</artifactId>
            <version>${scalatest-maven-plugin.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-testkit_2.11</artifactId>
            <version>${akka-testkit_2.11.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.11</artifactId>
            <version>${scalatest_2.11.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>clean install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <scalaCompatVersion>${maven-scala-plugin.scalaCompatVersion}</scalaCompatVersion>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <scalaVersion>${scala.version}</scalaVersion>
                    <args>
                        <arg>-target:jvm-1.8</arg>
                    </args>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.scalatest</groupId>
                <artifactId>scalatest-maven-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <junitxml>.</junitxml>
                    <filereports>WDF TestSuite.txt</filereports>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.scala-tools</groupId>
                <artifactId>maven-scala-plugin</artifactId>
                <configuration>
                    <scalaVersion>${scala.version}</scalaVersion>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
</project>

我错过了什么? 谢谢

【问题讨论】:

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


    【解决方案1】:

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

    警告

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

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

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

    另见:Akka: missing akka.version

    【讨论】:

    • 是否需要在项目中显式添加reference.conf?
    【解决方案2】:

    有类似的问题:

    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>
    

    【讨论】:

    • 你的插件仍然给我No configuration setting found for key 'akka.version',就像akka docs中的插件一样。
    • @DeanSchulze 你找到解决方案了吗?
    【解决方案3】:

    所以问题是在制作一个胖罐子时产生的,但没有以正确的方式处理 reference.conf

    解释来自@Zoltan 的回答:

    您的问题似乎是捆绑到一个 jar-with-dependencies 中,这会导致 Akka 出现问题,如文档中所述:

    警告

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

    我为 SBT 用户提供了一个不需要插件的解决方案。

    在 build.sbt 中,将 case "reference.conf" =&gt; 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】:

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

    【讨论】:

      【解决方案5】:

      添加以下插件:

      <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

      【讨论】:

      • 这对我有用!!如果您可以添加一些详细信息,则可能也可以节省其他一些详细信息。
      【解决方案6】:

      我试过这个插件,它很棒,但由于一些签名的 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 插件。只需将其添加到您的构建中,即可享受无缝的可运行 jar。这是我喜欢 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 应用程序即可使用此插件。只需在任何应用程序中使用它,它就可以发挥魅力。

      【讨论】:

        猜你喜欢
        • 2016-06-18
        • 2015-02-21
        • 2017-10-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        • 2018-04-15
        • 2013-05-17
        相关资源
        最近更新 更多