ktorio / ktor-init-tools

ktor project generator web page and IDEA plugin

Home Page:https://start.ktor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception when using "logging feature": "java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader"

karl-run opened this issue · comments

As erroneously opened in ktorio/ktor:867

Ktor Version

1.1.1

Ktor Engine Used(client or server and name)

io.ktor.server.netty.EngineMain

JVM Version, Operating System and Relevant Context

   openjdk version "1.8.0_192"
   OpenJDK Runtime Environment (build 1.8.0_192-b26)
   OpenJDK 64-Bit Server VM (build 25.192-b26, mixed mode)

OS: Linux 4.14.90-1-MANJARO

Feedback

I have created a completely fresh project using the IntelliJ Ktor-plugin's starter, only choosing "Logging feature" as additional features.

Starting the server without doing any changes gives me the following stack trace:

2019-01-13 16:51:11.390 [main] INFO  Application - No ktor.deployment.watch patterns specified, automatic reload is not active
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method.callMethod(CallerImpl.kt:71)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Method$Static.call(CallerImpl.kt:80)
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflect_api(KCallableImpl.kt:166)
	at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:110)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.callFunctionWithInjection(ApplicationEngineEnvironmentReloading.kt:347)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.executeModuleFunction(ApplicationEngineEnvironmentReloading.kt:297)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.instantiateAndConfigureApplication(ApplicationEngineEnvironmentReloading.kt:273)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.createApplication(ApplicationEngineEnvironmentReloading.kt:126)
	at io.ktor.server.engine.ApplicationEngineEnvironmentReloading.start(ApplicationEngineEnvironmentReloading.kt:245)
	at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:106)
	at io.ktor.server.netty.NettyApplicationEngine.start(NettyApplicationEngine.kt:18)
	at io.ktor.server.engine.ApplicationEngine$DefaultImpls.start$default(ApplicationEngine.kt:46)
	at io.ktor.server.netty.EngineMain.main(EngineMain.kt:17)
	at com.example.ApplicationKt.main(Application.kt:12)
Caused by: java.lang.ExceptionInInitializerError
	at com.example.ApplicationKt.module(Application.kt:27)
	at com.example.ApplicationKt.module$default(Application.kt:16)
	... 18 more
Caused by: java.lang.IllegalStateException: Failed to find HttpClientEngineContainer in classpath via ServiceLoader
	at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:28)
	... 20 more

Removing this section in Application.kt:

val client = HttpClient() {
    install(Logging) {
        level = LogLevel.HEADERS
    }
}

Allows me to start the server successfully.

Checking "Apache" in the wizard creates a runnable application. Which makes sense to me now that I understand the signature of io.ktor.client.HttpClient. But, it could probably be made more obvious in the wizard, same way that that the base-HttpClient is automatically selected when you select any of the features.

Feel free to close this as "user error".

For sure this is usability problem that need to be resolved somehow