scala - 缺少环境变量
问题描述
我正在使用库https://cir.is/docs/overview来加载我的环境变量,如下所示:
object EnvironmentLoader {
val db: ConfigValue[Postgres] =
(
env("POSTGRES_URL").as[NonEmptyString],
env("POSTGRES_USER").as[NonEmptyString],
env("POSTGRES_PW").as[DatabasePassword].secret
).parMapN(Postgres)
}
我在shell中设置了变量:
POSTGRES_URL=jdbc:postgresql://localhost:5432/users
POSTGRES_USER=dbuser
POSTGRES_PW=password
当我运行sbt test
它显示:
[error] - GET /user test with invalid UUID
[error] ConfigException$$anon$1: configuration loading failed with the following errors.
[error]
[error] - Missing environment variable POSTGRES_URL.
[error] - Missing environment variable POSTGRES_USER.
[error] - Missing environment variable POSTGRES_PW.
[error]
[error] ConfigException.scala:57 ciris.ConfigException$#apply
[error] ConfigError.scala:114 ciris.ConfigError#throwable
[error] ConfigValue.scala:176 ciris.ConfigValue#$anonfun$load$1
[error] Resource.scala:118 cats.effect.Resource#$anonfun$fold$1
[error] <snipped> cats.effect.internals.<...>
[error] JFunction0$mcV$sp.scala:18 scala.runtime.java8.JFunction0$mcV$sp#apply
[error] BlockContext.scala:94 scala.concurrent.BlockContext$#withBlockContext
[error] <snipped> cats.effect.internals.<...>
[error] <snipped> java.util.concurrent.<...>
如何设置环境变量sbt
?
解决方案
推荐阅读
- latex - 如何在表格 Latex 中使用逗号设置数字
- robots.txt - 允许文件夹,但不允许特定子文件夹
- ios - Cocoa pods 资源包 xcassets
- node.js - node.js、vue.js 和 express.js 堆栈开发
- java - Groovy - 如何创建带有变量的路径目录
- php - 表单不应包含额外字段 Symfony 4
- python - Python Pandas 2 列关系
- android - 在调用另一个类的 ViewModel 中实现 Dagger
- spring-boot - Spring Boot:使用 Thymeleaf 从会话中删除属性
- python-3.x - Urllib.request.urlopen().read 不起作用