【问题标题】:Message 'No configuration setting found for key' Akka-Http消息“找不到密钥的配置设置”Akka-Http
【发布时间】:2018-04-15 03:04:28
【问题描述】:

在我的项目中,我可以编译运行没有问题,我的项目是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.

因为失眠出现了这个:

我的 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 的 trait 中读取了我的配置,它有:

 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 执行应用程序

我用于测试的 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}
    }
  }
}

什么是错误?任何帮助我将不胜感激。谢谢!

【问题讨论】:

    标签: postgresql scala h2 slick akka-http


    【解决方案1】:

    似乎有些东西在配置中寻找一个名为 cors 的键但找不到它,在我的配置中我添加了:

      cors.allowed-origin = "*"
    

    一切正常!

    【讨论】:

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