问题
I have a Spring Boot application which fails to start in IntelliJ 2017.1.5, as soon as I add the Spring Boot developer tools to the Gradle build like this:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.apache.httpcomponents:httpclient:4.5.3")
compile("com.fasterxml.jackson.core:jackson-databind:2.8.8.1")
compile("commons-validator:commons-validator:1.6")
// This line breaks IntelliJ compatibility:
optional("org.springframework.boot:spring-boot-devtools")
optional("org.springframework.boot:spring-boot-configuration-processor")
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit:4.12")
}
Without the spring-boot-devtools
everything is fine, as soon as I add them, starting the application (after refreshing the Gradle project in IntelliJ) fails with a NoClassDefFoundError
:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/web/client/RestTemplateBuilder
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.web.client.RestTemplateBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I'm pretty sure it's an IntelliJ issue, because the same application runs fine in Eclipse with the Spring Boot developer tools enabled.
Any ideas how to fix this?
回答1:
I was able to resolve this problem by changing the dependency to the spring-boot-devtools
to:
runtime("org.springframework.boot:spring-boot-devtools")
Instead of
optional("org.springframework.boot:spring-boot-devtools")
来源:https://stackoverflow.com/questions/45016574/intellij-fails-to-start-spring-boot-gradle-application-when-using-spring-boot-de