在 Heroku 上部署 ktor 应用程序时出现 JDBC_DATABASE_URL 错误

Posted

技术标签:

【中文标题】在 Heroku 上部署 ktor 应用程序时出现 JDBC_DATABASE_URL 错误【英文标题】:JDBC_DATABASE_URL error to deploy ktor app on Heroku 【发布时间】:2020-08-29 18:30:38 【问题描述】:

我正在尝试将 ktor rest-API 部署到 heroku 并且 heroku 生成了一个 DATABASE_URL 但是当我尝试运行它时会出现此错误说 driverClassName 需要 jdbcUrl

State changed from crashed to starting
2020-05-13T14:01:34.459797+00:00 app[web.1]: 2020-05-13 14:01:34.457 [main] TRACE Application - 
2020-05-13T14:01:34.459822+00:00 app[web.1]: # application.conf @ jar:file:/app/scienta-0.0.1.jar!/application.conf: 7
2020-05-13T14:01:34.459823+00:00 app[web.1]: "application" : 
2020-05-13T14:01:34.459823+00:00 app[web.1]: # application.conf @ jar:file:/app/scienta-0.0.1.jar!/application.conf: 8
2020-05-13T14:01:34.459823+00:00 app[web.1]: "modules" : [
2020-05-13T14:01:34.459824+00:00 app[web.1]: # application.conf @ jar:file:/app/scienta-0.0.1.jar!/application.conf: 8
2020-05-13T14:01:34.459824+00:00 app[web.1]: "co.scienta.ridesharecompare.ApplicationKt.module"
2020-05-13T14:01:34.459825+00:00 app[web.1]: ]
2020-05-13T14:01:34.459825+00:00 app[web.1]: ,
2020-05-13T14:01:34.459826+00:00 app[web.1]: # application.conf @ jar:file:/app/scienta-0.0.1.jar!/application.conf: 2
2020-05-13T14:01:34.459826+00:00 app[web.1]: "deployment" : 
2020-05-13T14:01:34.459826+00:00 app[web.1]: # application.conf @ jar:file:/app/scienta-0.0.1.jar!/application.conf: 5
2020-05-13T14:01:34.459827+00:00 app[web.1]: "host" : "0.0.0.0",
2020-05-13T14:01:34.459827+00:00 app[web.1]: # env var PORT
2020-05-13T14:01:34.459827+00:00 app[web.1]: "port" : "52703"
2020-05-13T14:01:34.459827+00:00 app[web.1]: ,
2020-05-13T14:01:34.459828+00:00 app[web.1]: # Content hidden
2020-05-13T14:01:34.459828+00:00 app[web.1]: "security" : "***"
2020-05-13T14:01:34.459828+00:00 app[web.1]: 
2020-05-13T14:01:34.459829+00:00 app[web.1]:
2020-05-13T14:01:34.681389+00:00 app[web.1]: 2020-05-13 14:01:34.680 [main] INFO  Application - No ktor.deployment.watch patterns specified, automatic reload is not active
2020-05-13T14:01:35.287566+00:00 app[web.1]: 2020-05-13 14:01:35.285 [main] DEBUG com.zaxxer.hikari.HikariConfig - Driver class org.postgresql.Driver found in Thread context class loader sun.misc.Launcher$AppClassLoader@70dea4e
2020-05-13T14:01:35.298702+00:00 app[web.1]: 2020-05-13 14:01:35.298 [main] ERROR com.zaxxer.hikari.HikariConfig - HikariPool-1 - jdbcUrl is required with driverClassName.
2020-05-13T14:01:35.299261+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2020-05-13T14:01:35.299475+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-05-13T14:01:35.299539+00:00 app[web.1]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2020-05-13T14:01:35.299588+00:00 app[web.1]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2020-05-13T14:01:35.299629+00:00 app[web.1]: at java.lang.reflect.Method.invoke(Method.java:498)
2020-05-13T14:01:35.299675+00:00 app[web.1]: at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:97)
2020-05-13T14:01:35.299730+00:00 app[web.1]: at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:106)
2020-05-13T14:01:35.299767+00:00 app[web.1]: at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:106)
2020-05-13T14:01:35.299815+00:00 app[web.1]: at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:152)
2020-05-13T14:01:35.299866+00:00 app[web.1]: at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
2020-05-13T14:01:35.299913+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:392)
2020-05-13T14:01:35.299992+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:340)
2020-05-13T14:01:35.300072+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:33)
2020-05-13T14:01:35.300149+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:287)
2020-05-13T14:01:35.300224+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1$$special$$inlined$forEach$lambda$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
2020-05-13T14:01:35.300302+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:320)
2020-05-13T14:01:35.300382+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.access$avoidingDoubleStartupFor(ApplicationEngineEnvironmentReloading.kt:33)
2020-05-13T14:01:35.300457+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:286)
2020-05-13T14:01:35.300534+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading$instantiateAndConfigureApplication$1.invoke(ApplicationEngineEnvironmentReloading.kt:33)
2020-05-13T14:01:35.300608+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.avoidingDoubleStartup(ApplicationEngineEnvironmentReloading.kt:302)
2020-05-13T14:01:35.300683+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:284)
2020-05-13T14:01:35.300757+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:137)
2020-05-13T14:01:35.300854+00:00 app[web.1]: at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:257)
2020-05-13T14:01:35.300928+00:00 app[web.1]: at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:126)
2020-05-13T14:01:35.300983+00:00 app[web.1]: at io.ktor.server.netty.EngineMain.main(EngineMain.kt:26)
2020-05-13T14:01:35.301239+00:00 app[web.1]: Caused by: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName.
2020-05-13T14:01:35.301313+00:00 app[web.1]: at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:954)
2020-05-13T14:01:35.301412+00:00 app[web.1]: at co.scienta.ridesharecompare.database.DatabaseFactory.hikari(DatabaseFactory.kt:32)
2020-05-13T14:01:35.301493+00:00 app[web.1]: at co.scienta.ridesharecompare.database.DatabaseFactory.init(DatabaseFactory.kt:14)
2020-05-13T14:01:35.301566+00:00 app[web.1]: at co.scienta.ridesharecompare.ApplicationKt.module(Application.kt:55)

有谁知道在 JDBC_DATABASE_URL 的配置变量中添加什么

【问题讨论】:

【参考方案1】:

您的 DATABASE_URL 环境变量中是否有类似 jdbc:postgresql:database 的内容?将其放入 JDBC_DATABASE_URL。请在 ktor.io 文档中搜索关于部署到 Heroku 的 JDBC_DATABASE_URL:https://ktor.io/servers/deploy/hosting/heroku.html

【讨论】:

如果你想在 heroku 上部署 ktor 应用 .. 请阅读这篇关于 ktor 应用部署的中型博客nameisjayant.medium.com/…

以上是关于在 Heroku 上部署 ktor 应用程序时出现 JDBC_DATABASE_URL 错误的主要内容,如果未能解决你的问题,请参考以下文章

在heroku上部署应用程序时出现过时的纱线锁文件错误

在 Heroku 上部署 React 应用程序和 Nginx 时出现问题

在 Heroku 上部署时出现 Django 1.7 迁移错误

如何解决在 Heroku 上部署 React 应用程序时出现的错误

在 heroku 上部署反应应用程序时出现问题 - 控制台上的错误代码 503

在heroku上使用vue应用程序部署rails 6时出现node-gyp错误