代码之家  ›  专栏  ›  技术社区  ›  Jayant Kumar

线程“main”java中出现异常。朗,反思一下。InvocationTargetException-Ktor应用程序

  •  0
  • Jayant Kumar  · 技术社区  · 5 年前

    下面是我在heroku上部署ktor应用程序(rest api)时遇到的一个例外。它在heroku本地服务器上运行良好,但在服务器上出现问题。我在这里使用postgreSql数据库

    here you can get the full source code 👇🏻 
    

    https://github.com/nameisjayant/Ktor-Todo-Api

    > 2021-06-06T14:05:05.948824+00:00 app[web.1]: at
    > com.codingwithjks.repository.DatabaseFactory.hikari(DatabaseFactory.kt:26)
    >     2021-06-06T14:05:05.948898+00:00 app[web.1]: at com.codingwithjks.repository.DatabaseFactory.init(DatabaseFactory.kt:16)
    >     2021-06-06T14:05:05.948953+00:00 app[web.1]: at com.codingwithjks.ApplicationKt.module(Application.kt:32)
    >     2021-06-06T14:05:05.948994+00:00 app[web.1]: at com.codingwithjks.ApplicationKt.module$default(Application.kt:28)
    >     2021-06-06T14:05:05.949068+00:00 app[web.1]: ... 24 more
    >     2021-06-06T14:05:09.000000+00:00 app[api]: Build succeeded
    >     2021-06-06T14:05:12.624192+00:00 heroku[web.1]: Process exited with status 1
    >     2021-06-06T14:05:12.701399+00:00 heroku[web.1]: State changed from starting to crashed
    >     2021-06-06T14:05:28.888453+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=36434e2c-f89b-4ff7-bfc3-89cc3b927211 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=https
    >     2021-06-06T14:05:29.482958+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=c8c0bff6-91c6-4838-a5d7-3e83cca5f1dd fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=https
    >     2021-06-06T14:12:03.000000+00:00 app[api]: Build started by user jayntkumar99@gmail.com
    >     2021-06-06T14:13:02.973949+00:00 app[api]: Deploy d0fbe4c4 by user jayntkumar99@gmail.com
    >     2021-06-06T14:13:02.973949+00:00 app[api]: Release v10 created by user jayntkumar99@gmail.com
    >     2021-06-06T14:13:03.838082+00:00 heroku[web.1]: State changed from crashed to starting
    >     2021-06-06T14:13:07.347769+00:00 heroku[web.1]: Starting process with command `./build/install/example/bin/example`
    >     2021-06-06T14:13:09.742957+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will
    > override them.
    >     2021-06-06T14:13:09.743159+00:00 app[web.1]: bash: ./build/install/example/bin/example: No such file or directory
    >     2021-06-06T14:13:09.802293+00:00 heroku[web.1]: Process exited with status 127
    >     2021-06-06T14:13:09.886995+00:00 heroku[web.1]: State changed from starting to crashed
    >     2021-06-06T14:13:30.000000+00:00 app[api]: Build succeeded
    >     2021-06-06T14:13:40.561950+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=3064eaba-777b-4b6d-bd79-855d23dfe140 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=https
    >     2021-06-06T14:13:41.107491+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=fe5be84d-6e79-4eda-aae4-c4b679ec2c62 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=https
    >     2021-06-06T14:14:03.555698+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=cc4d10b8-6650-400b-ad87-5f36b144ec44 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=http
    >     2021-06-06T14:14:04.222065+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=c83df707-fe4f-47a1-a6c9-a39a23c83cc5 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=http
    >     2021-06-06T14:14:07.733808+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=78efe78b-a180-4592-844e-eeb14e317ae2 fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=http
    >     2021-06-06T14:14:08.394252+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico"
    > host=todo-rest-api-23242.herokuapp.com
    > request_id=2d2e989c-f695-4311-b3be-644381a2ea9a fwd="103.198.173.200"
    > dyno= connect= service= status=503 bytes= protocol=http
    >     2021-06-06T14:20:13.438814+00:00 heroku[web.1]: State changed from crashed to starting
    >     2021-06-06T14:20:17.000000+00:00 app[api]: Build started by user jayntkumar99@gmail.com
    >     2021-06-06T14:20:17.780691+00:00 heroku[web.1]: Starting process with command `./build/install/example/bin/example`
    >     2021-06-06T14:20:21.761892+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will
    > override them.
    >     2021-06-06T14:20:21.762092+00:00 app[web.1]: bash: ./build/install/example/bin/example: No such file or directory
    >     2021-06-06T14:20:21.840577+00:00 heroku[web.1]: Process exited with status 127
    >     2021-06-06T14:20:21.910863+00:00 heroku[web.1]: State changed from starting to crashed
    >     2021-06-06T14:21:14.241869+00:00 app[api]: Release v11 created by user jayntkumar99@gmail.com
    >     2021-06-06T14:21:14.241869+00:00 app[api]: Deploy 8bf5ea75 by user jayntkumar99@gmail.com
    >     2021-06-06T14:21:14.497150+00:00 heroku[web.1]: State changed from crashed to starting
    >     2021-06-06T14:21:17.982363+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/example-0.0.1-all.jar`
    >     2021-06-06T14:21:20.424533+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will
    > override them.
    >     2021-06-06T14:21:20.428220+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2
    > -Dfile.encoding=UTF-8
    >     2021-06-06T14:21:20.989769+00:00 app[web.1]: 2021-06-06 14:21:20.986 [main] TRACE Application - {
    >     2021-06-06T14:21:20.989792+00:00 app[web.1]: # application.conf @
    

    jar:file:/app/build/libs/example-0.0.1-all。罐子/应用形态:6 >2021-06-06T14:21:20.989793+00:00应用程序[web.1]:“应用程序”:{ >2021-06-06T14:21:20.989794+00:00应用程序[web.1]:#应用程序。形态@ jar:file:/app/build/libs/example-0.0.1-all。罐子/应用形态:7 >2021-06-06T14:21:20.989794+00:00应用程序[web.1]:“模块”:[ >2021-06-06T14:21:20.989795+00:00应用程序[web.1]:#应用程序。形态@ jar:file:/app/build/libs/example-0.0.1-all。罐子/应用形态:7 >2021-06-06T14:21:20.989795+00:00应用程序[web.1]:“com.codingwithjks.ApplicationKt.module” >2021-06-06T14:21:20.989796+00:00应用程序[web.1]:] >2021-06-06T14:21:20.989796+00:00应用程序[web.1]:}, >2021-06-06T14:21:20.989797+00:00应用程序[web.1]:#应用程序。形态@ jar:file:/app/build/libs/example-0.0.1-all。罐子/应用形态:2 >2021-06-06T14:21:20.989797+00:00应用程序[web.1]:“部署”:{ >2021-06-06T14:21:20.989797+00:00应用程序[web.1]:#环境变量端口 >2021-06-06T14:21:20.989798+00:00应用程序[web.1]:“端口”:“44723” >2021-06-06T14:21:20.989798+00:00应用程序[web.1]:}, >2021-06-06T14:21:20.989799+00:00应用程序[web.1]:#内容隐藏 >2021-06-06T14:21:20.989799+00:00应用程序[web.1]:“安全性”:“***” >2021-06-06T14:21:20.989799+00:00应用程序[web.1]:} >2021-06-06T14:21:20.989800+00:00应用程序[web.1]: >2021-06-06T14:21:21.096772+00:00应用程序[web.1]:2021-06-06 14:21:21.096[main]信息应用程序-自动加载被禁用,因为 >开发模式已关闭。 >2021-06-06T14:21:21.599262+00:00应用程序[web.1]:线程“main”java中的异常。朗,反思一下。调用目标异常 >2021-06-06T14:21:21.599515+00:00应用程序[web.1]:太阳报。反映NativeMethodAccessorImpl。invoke0(本机方法) >2021-06-06T14:21:21.599646+00:00应用程序[web.1]:太阳报。反映NativeMethodAccessorImpl。调用(NativeMethodAccessorImpl.java:62) >2021-06-06T14:21:21.599701+00:00应用程序[web.1]:在太阳。反映DelegatingMethodAccessorImpl。调用(DelegatingMethodAccessorImpl.java:43) >2021-06-06T14:21:21.599802+00:00应用程序[web.1]:在java。朗,反思一下。方法调用(Method.java:498) >2021-06-06T14:21:21.599827+00:00应用程序[web.1]:在科特林。反映jvm。内部的电话。CallerImpl$方法。callMethod(CallerImpl.kt:97) >2021-06-06T14:21:21.599942+00:00应用程序[web.1]:在科特林。反映jvm。内部的电话。CallerImpl$Method$Static。通话(CallerImpl.kt:106) >2021-06-06T14:21:21.600007+00:00应用程序[web.1]:在科特林。反映jvm。内部的KCallableImpl。callDefaultMethod$kotlin_反射(KCallableImpl.kt:173) >2021-06-06T14:21:21.600105+00:00应用程序[web.1]:在科特林。反映jvm。内部的KCallableImpl。callBy(KCallableImpl.kt:112) >2021-06-06T14:21:21.600196+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。callFunctionWithInjection(ApplicationEngineEnvironment重新加载.kt:406) >2021-06-06T14:21:21.600282+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:360) >2021-06-06T14:21:21.600378+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。访问$executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:35) >2021-06-06T14:21:21.600475+00:00应用程序[web.1]:在io。克托尔。服务器发动机ApplicationEngineEnvironment正在重新加载$launchModuleByName$1。调用(ApplicationEngineEnvironmentReloading.kt:311) >2021-06-06T14:21:21.600551+00:00应用程序[web.1]:在io。克托尔。服务器发动机ApplicationEngineEnvironment正在重新加载$launchModuleByName$1。调用(ApplicationEngineEnvironmentReloading.kt:35) >2021-06-06T14:21:21.600660+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。避免双重启动(ApplicationEngineering重新加载。kt:335) >2021-06-06T14:21:21.600737+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。launchModuleByName(ApplicationEngineenEnvironmentReloading.kt:310) >2021-06-06T14:21:21.600827+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。访问$launchModuleByName(ApplicationEngineenEnvironmentReloading.kt:35) >2021-06-06T14:21:21.600921+00:00应用程序[web.1]:在io。克托尔。服务器发动机ApplicationEngineenEnvironment正在重新加载$InstanceAndConfigureApplication1。调用(ApplicationEngineEnvironmentReloading.kt:299) >2021-06-06T14:21:21.601006+00:00应用程序[web.1]:在io。克托尔。服务器发动机ApplicationEngineenEnvironment正在重新加载$InstanceAndConfigureApplication1。调用(ApplicationEngineEnvironmentReloading.kt:35) >2021-06-06T14:21:21.601100+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。避免双重启动(ApplicationEngineering重新加载.kt:317) >2021-06-06T14:21:21.601183+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。InstanceAndConfigureApplication(ApplicationEngineenEnvironmentReloading.kt:297) >2021-06-06T14:21:21.601285+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。createApplication(ApplicationEngineEnvironmentReloading.kt:138) >2021-06-06T14:21:21.601358+00:00应用程序[web.1]:在io。克托尔。服务器发动机应用程序工程环境重新加载。启动(ApplicationEngineEnvironment重新加载.kt:270) >2021-06-06T14:21:21.601444+00:00应用程序[web.1]:在io。克托尔。服务器内蒂。NettyApplicationEngine。启动(NettyApplicationEngine.kt:160) >2021-06-06T14:21:21.601528+00:00应用程序[web.1]:在io。克托尔。服务器内蒂。工程师。主要设备(发动机主要设备kt:26) >2021-06-06T14:21:21.601783+00:00应用程序[web.1]:原因:java。lang.NullPointerException >2021-06-06T14:21:21.601871+00:00应用程序[web.1]:在太阳。杂项。Launcher$AppClassLoader。loadClass(Launcher.java:328) >2021-06-06T14:21:21.602010+00:00应用程序[web.1]:在java。lang.ClassLoader。loadClass(ClassLoader.java:351) >2021-06-06T14:21:21.602109+00:00应用程序[web.1]:在com上。扎克瑟。希卡里。HikariConfig。attemptFromContextLoader(HikariConfig.java:970) >2021-06-06T14:21:21.602190+00:00应用程序[web.1]:在com上。扎克瑟。希卡里。HikariConfig。setDriverClassName(HikariConfig.java:480) >2021-06-06T14:21:21.602273+00:00应用程序[web.1]:在com上。用JKS编码。存储库。数据库工厂。hikari(DatabaseFactory.kt:26) >2021-06-06T14:21:21.602361+00:00应用程序[web.1]:在com上。用JKS编码。存储库。数据库工厂。init(DatabaseFactory.kt:16) >2021-06-06T14:21:21.602442+00:00应用程序[web.1]:在com上。用JKS编码。应用程序KT。模块(Application.kt:32) >2021-06-06T14:21:21.602529+00:00应用程序[web.1]:在com上。用JKS编码。应用程序KT。模块$default(Application.kt:28) >2021-06-06T14:21:21.602629+00:00应用程序[web.1]:。。。还有24个 >2021-06-06T14:21:27.903731+00:00 heroku[web.1]:进程已退出,状态为1 >2021-06-06T14:21:27.974849+00:00 heroku[web.1]:状态从开始更改为崩溃 >2021-06-06T14:21:42.000000+00:00应用程序[api]:构建成功 >2021-06-06T14:21:58.940235+00:00 heroku[路由器]:at=error code=H10 desc=“App crash”method=GET path=“/” >主机=todo-rest-api-23242。希罗库普。通用域名格式 >请求id=631a1616-282e-42cc-9389-53795848093d fwd=“103.198.173.200” >dyno=连接=服务=状态=503字节=协议=http >2021-06-06T14:21:59.731558+00:00 heroku[路由器]:at=错误代码=H10 desc=“App crash”method=GET path=“/favicon.ico” >主机=todo-rest-api-23242。希罗库普。通用域名格式 >请求id=17a44432-c880-4e11-a614-b0c8ec88033a fwd=“103.198.173.200” >dyno=连接=服务=状态=503字节=协议=http >2021-06-06T14:22:01.657491+00:00 heroku[路由器]:at=error code=H10 desc=“App crash”method=GET path=“/” >主机=todo-rest-api-23242。希罗库普。通用域名格式 >请求id=e1545ce7-1056-499e-a480-0c31fec0de9d fwd=“103.198.173.200” >dyno=连接=服务=状态=503字节=协议=http >2021-06-06T14:22:02.340307+00:00 heroku[路由器]:at=错误代码=H10 desc=“App crash”method=GET path=“/favicon.ico” >主机=todo-rest-api-23242。希罗库普。通用域名格式 >请求id=b4ee0d3b-3856-452d-abcf-ac3e10511d17 fwd=“103.198.173.200” >dyno=连接=服务=状态=503字节=协议=http

    数据库工厂类

    package com.codingwithjks.repository
    
    import com.codingwithjks.data.table.TodoTable
    import com.codingwithjks.data.table.UserTable
    import com.zaxxer.hikari.HikariConfig
    import com.zaxxer.hikari.HikariDataSource
    import kotlinx.coroutines.Dispatchers
    import kotlinx.coroutines.withContext
    import org.jetbrains.exposed.sql.Database
    import org.jetbrains.exposed.sql.SchemaUtils
    import org.jetbrains.exposed.sql.transactions.transaction
    
    object DatabaseFactory {
    
        fun init(){
            Database.connect(hikari())
            transaction {
                SchemaUtils.create(UserTable)
                SchemaUtils.create(TodoTable)
            }
        }
    
    
        private fun hikari():HikariDataSource {
            val config = HikariConfig()
            config.driverClassName = System.getenv("JDBC_DRIVER_2")
            config.jdbcUrl = System.getenv("JDBC_DATABASE_URL_2")
            config.maximumPoolSize = 3
            config.isAutoCommit = true
            config.transactionIsolation = "TRANSACTION_REPEATABLE_READ"
            config.validate()
    
            return HikariDataSource(config)
        }
    
        suspend fun <T> dbQuery(block : ()->T):T =
            withContext(Dispatchers.IO){
                transaction {
                    block()
                }
            }
    }
    

    应用kt文件

    package com.codingwithjks
    
    import com.codingwithjks.auth.JwtService
    import com.codingwithjks.auth.MySession
    import com.codingwithjks.auth.hash
    import com.codingwithjks.repository.DatabaseFactory
    import com.codingwithjks.repository.TodoRepository
    import com.codingwithjks.repository.UserRepository
    import com.codingwithjks.routes.todos
    import com.codingwithjks.routes.users
    import io.ktor.application.*
    import io.ktor.response.*
    import io.ktor.request.*
    import io.ktor.routing.*
    import io.ktor.http.*
    import io.ktor.locations.*
    import io.ktor.sessions.*
    import io.ktor.auth.*
    import io.ktor.auth.jwt.*
    import io.ktor.gson.*
    import io.ktor.features.*
    
    fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
    
    @OptIn(KtorExperimentalLocationsAPI::class)
    @Suppress("unused") // Referenced in application.conf
    @kotlin.jvm.JvmOverloads
    fun Application.module(testing: Boolean = false) {
        install(Locations) {
        }
    
        DatabaseFactory.init()
        val userDb = UserRepository()
        val todoDb = TodoRepository()
        val jwt = JwtService()
        val hashFunction = {s:String -> hash(s)}
        install(Sessions) {
            cookie<MySession>("MY_SESSION") {
                cookie.extensions["SameSite"] = "lax"
            }
        }
    
        install(Authentication) {
            jwt("jwt") {
                verifier(jwt.verifier)
                realm = "Todo Server"
                validate {
                    val payload = it.payload
                    val claim = payload.getClaim("id")
                    val claimString = claim.asInt()
                    val user = userDb.findUser(claimString)
                    user
                }
            }
        }
    
        install(ContentNegotiation) {
            gson {
                setPrettyPrinting()
                disableHtmlEscaping()
            }
        }
    
        routing {
            get("/"){
                call.respondText("Hello world..")
            }
            users(userDb,todoDb,jwt,hashFunction)
            todos(todoDb,userDb)
        }
    }
    
    const val API_VERSION = "/v1"
    

    请帮帮我:)

    0 回复  |  直到 5 年前
    推荐文章