我有一个 Spring Boot 应用程序无法在 IntelliJ 2017.1.5 中启动,只要我将 Spring Boot 开发人员工具添加到 Gradle 构建中,如下所示:
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")
}
如果没有spring-boot-devtools
一切都很好,只要我添加它们,启动应用程序(在 IntelliJ 中刷新 Gradle 项目后)就会失败,并显示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
我很确定这是一个 IntelliJ 问题,因为启用了 Spring Boot 开发人员工具后,相同的应用程序在 Eclipse 中运行良好。
任何想法如何解决这一问题?