NoClassDefFoundError: kotlin/reflect/full/KClasses with 2.0.0.M3, Webflux and Kotlin
See original GitHub issueHi,
I have the following demo application
package de.springbootbuch.webflux_kotlin
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.MediaType.TEXT_HTML
import org.springframework.stereotype.Component
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse.ok
import org.springframework.web.reactive.function.server.router
import reactor.core.publisher.Mono
@SpringBootApplication
class Application {
@Component
class Handler {
fun sayHello(req: ServerRequest) =
ok().body(
Mono.just("Hello, ${req.queryParam("name").orElse("World")}"),
String::class.java
)
fun andGoodbye(req: ServerRequest) =
ok().body(
Mono.just("Goodbye"),
String::class.java
)
}
@Configuration
class RoutesConfig(val handler: Handler) {
@Bean
fun routes() = router {
("/greetings" and accept(TEXT_HTML)).nest {
GET("/hello", handler::sayHello)
GET("/goodbye", handler::andGoodbye)
}
}
}
}
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
Build with Gradle:
buildscript {
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
}
ext {
ktVersion = "1.1.3"
springBootVersion = "2.0.0.M3"
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$ktVersion"
classpath "org.jetbrains.kotlin:kotlin-allopen:$ktVersion"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
apply plugin: "kotlin"
apply plugin: "kotlin-spring"
apply plugin: "org.springframework.boot"
apply plugin: "io.spring.dependency-management"
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
jar {
baseName = "webflux_kotlin"
version = "0.0.1-SNAPSHOT"
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-snapshot" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$ktVersion"
compile "org.springframework.boot:spring-boot-starter-webflux"
}
(Full source is here https://github.com/springbootbuch/webflux_kotlin).
It compiles and builds fine with Spring Boot 2.0.0.M2 and 2.0.0.M3, but doesn’t run anymore with 2.0.0.M3. It fails to instantiate Jacksons ObjectMapper
:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'jacksonObjectMapper' threw exception; nested exception is java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
and earlier to that I see a ClassCastException
:
2017-08-09 10:17:43.057 WARN 14058 --- [ main] o.s.b.c.e.EventPublishingRunListener : Error calling ApplicationEventListener
java.lang.ClassCastException: org.springframework.boot.context.event.ApplicationFailedEvent cannot be cast to org.springframework.boot.web.context.WebServerInitializedEvent
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:159) [spring-context-5.0.0.RC3.jar!/:5.0.0.RC3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.0.0.RC3.jar!/:5.0.0.RC3]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) [spring-context-5.0.0.RC3.jar!/:5.0.0.RC3]
at org.springframework.boot.context.event.EventPublishingRunListener.finished(EventPublishingRunListener.java:114) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplicationRunListeners.callFinishedListener(SpringApplicationRunListeners.java:79) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplicationRunListeners.finished(SpringApplicationRunListeners.java:72) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:803) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1245) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1233) [spring-boot-2.0.0.M3.jar!/:2.0.0.M3]
at de.springbootbuch.webflux_kotlin.ApplicationKt.main(Application.kt:44) [classes!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [webflux_kotlin.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [webflux_kotlin.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [webflux_kotlin.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [webflux_kotlin.jar:na]
The full stack trace is attached stacktrace.txt.
Thanks for looking at that issue.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This looks to be due to a change in Spring Framework as it also fails, although slightly differently, with Boot 2.0 M2 and Spring Framework 5.0 RC3.
It works fine with Spring Boot 2.0 M3 if you add a dependency on
kotlin-reflect
:@sdeleuze may well be able to explain why the Framework now requires
kotlin-reflect
.Thanks for the detailed description of the problem and the sample project. The
ClassCastException
is due to SPR-15838. I think it’s unrelated to theNoClassDefFoundError
.