消息'未找到密钥'的配置设置。阿卡-HTTP

时间:2017-11-02 14:34:14

标签: postgresql scala h2 slick akka-http

在我的项目中,我可以编译并运行没有问题,我的项目是akka-http中的项目,我提供json类型的服务,但是在调用服务时出现此错误:

> run
[info] Running net.claritysales.api.Main
[DEBUG] [11/02/2017 11:08:32.360] [run-main-0] [EventStream(akka://default)] logger log1-Logging$DefaultLogger started
[DEBUG] [11/02/2017 11:08:32.361] [run-main-0] [EventStream(akka://default)] Default Loggers started
[DEBUG] [11/02/2017 11:08:33.253] [run-main-0] [AkkaSSLConfig(akka://default)] Initializing AkkaSSLConfig extension...
[DEBUG] [11/02/2017 11:08:33.258] [run-main-0] [AkkaSSLConfig(akka://default)] buildHostnameVerifier: created hostname verifier: com.typesafe.sslconfig.ssl.DefaultHostnameVerifier@5160a3bd
[DEBUG] [11/02/2017 11:08:34.687] [default-akka.actor.default-dispatcher-5] [akka://default/system/IO-TCP/selectors/$a/0] Successfully bound to /127.0.0.1:9000
[DEBUG] [11/02/2017 11:08:40.607] [default-akka.actor.default-dispatcher-5] [akka://default/system/IO-TCP/selectors/$a/0] New connection accepted
[ERROR] [11/02/2017 11:08:41.795] [default-akka.actor.default-dispatcher-5] [akka.actor.ActorSystemImpl(default)] Error during processing of request: 'No configuration setting found for key 'c
ors''. Completing with 500 Internal Server Error response.
[ERROR] [11/02/2017 11:08:43.467] [default-akka.actor.default-dispatcher-5] [akka.actor.ActorSystemImpl(default)] Error during processing of request: 'No configuration setting found for key 'c
ors''. Completing with 500 Internal Server Error response.
[DEBUG] [11/02/2017 11:09:49.232] [default-akka.actor.default-dispatcher-5] [akka://default/user/StreamSupervisor-0/flow-1-0-unknown-operation] Aborting tcp connection to /127.0.0.1:64741 beca
use of upstream failure: HTTP idle-timeout encountered, no bytes passed in the last 1 minute. This is configurable by akka.http.[server|client].idle-timeout.

因为失眠会出现:

enter image description here

我的application.conf是:

akka {
  loglevel = DEBUG
}

http {

  interface = "localhost"
  interface = ${?HTTP_INTERFACE}
  port = 9000
  port = ${?HTTP_PORT}

}

database = {
     cs {
         profile = "slick.jdbc.PostgresProfile$"
       db {
         url = "jdbc:postgresql://localhost:5432/cs2_company"
         url = ${?PSQL_URL}
         user = "postgres"
         user = ${?PSQL_USER}
         password = "qwerty"
         password = ${?PSQL_PASSWORD}
       }
     }
}

我从名为Config的特征中读取了我的配置,它具有:

 package net.cs.api.utils

import com.typesafe.config.ConfigFactory

trait Config {
  private val config = ConfigFactory.load()
  private val httpConfig = config.getConfig("http")
  private val databaseConfig = config.getConfig("database.cs")

  val httpHost = httpConfig.getString("interface")
  val httpPort = httpConfig.getInt("port")

  val jdbcUrl = databaseConfig.getString("db.url")
  val dbUser = databaseConfig.getString("db.user")
  val dbPassword = databaseConfig.getString("db.password")
}

另外我在测试资源中有另一个application.conf文件,因为我想用H2执行测试并用Postgres执行应用程序

enter image description here

我的application.conf测试是:

akka {
  loglevel = WARNING
}

database = {
  cs {
    profile = "slick.jdbc.H2Profile$"
    db {
      driver = "org.h2.Driver"
      url = "jdbc:h2:mem:cs2_company;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;IGNORECASE=TRUE;DATABASE_TO_UPPER=false"
      url = ${?PSQL_TEST_URL}
      user = "sales"
      user = ${?PSQL_TEST_USER}
      password = "sales"
      password = ${?PSQL_TEST_PASSWORD}
    }
  }
}

错误是什么?任何帮助,我会很感激。谢谢!

1 个答案:

答案 0 :(得分:1)

似乎有些东西在配置中找到了一个名为cors的密钥而无法找到它,在我添加的配置中:

  cors.allowed-origin = "*"
一切正常!