1. 程式人生 > >Akka HTTP部署報錯:Could not resolve substitution to a value: ${akka.stream.blocking-io-dispatcher}

Akka HTTP部署報錯:Could not resolve substitution to a value: ${akka.stream.blocking-io-dispatcher}

在idea中使用akka http完成服務端rest介面的開發與測試後,接著就可以部署到Linux伺服器上進行測試了,因為沒有限定pom中依賴包的scope為provided,所以打包時將依賴jar包也打進了專案jar包,方便執行測試,但是專案jar包較大,後續再分離依賴的jar包。打包時候pom的build部分如下:

<build>
  <resources>
    <resource>
      <directory>src/main/resources</directory>//這個地方是把resources下的配置檔案打進包裡
    </resource>
  </resources>
  <sourceDirectory>src/main/scala</sourceDirectory>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.3</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>com.xxx.bigdata.server.HbaseServer</mainClass>//執行的主類
              </transformer>
              ========================================================
            </transformers>
          </configuration>
        </execution>
      </executions>
    </plugin>

    <plugin>
      <groupId>org.scala-tools</groupId>
      <artifactId>maven-scala-plugin</artifactId>
      <version>2.15.2</version>
      <executions>
        <execution>
          <goals>
            <goal>compile</goal>
            <goal>testCompile</goal>
          </goals>
        </execution>
      </executions>
      <configuration>
        <scalaVersion>${scala.version}</scalaVersion>
        <args>
          <arg>-target:jvm-1.8</arg>
        </args>
      </configuration>
    </plugin>
  </plugins>
</build>

執行jar包:java -jar xxx.jar 結果報錯:Could not resolve substitution to a value: ${akka.stream.blocking-io-dispatcher};

解決辦法:在上面pom中的橫線處(======)新增

<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
  <resource>reference.conf</resource>
</transformer>

即可,在瀏覽器輸入get請求連結測試(此rest介面功能是:根據rowkey查hbase表返回json字串):

成功返回結果。

說明一點:關於akka http的部署,官網中對akka http的部署沒有明確說明,akka http可以看成是通用工具包,作為http層的整合工具。如果你有WEB應用,可以把akka http整合到你的WEB應用中,這樣akka http服務隨著WEB工程的部署而部署。如果沒有WEB工程那麼可以採用java -jar的方式執行你的akka http服務。