我有一个Spring Boot应用程序,它无法在Gradle 2017.1.5中启动,只要我将Spring Boot developer tools添加到IntelliJ版本中,如下所示:
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 developer tools的情况下,相同的应用程序在Eclipse中运行得很好。
有什么办法解决这个问题吗?
发布于 2017-07-31 23:46:18
我能够解决这个问题,方法是将spring-boot-devtools的依赖项改为:
runtime("org.springframework.boot:spring-boot-devtools")而不是
optional("org.springframework.boot:spring-boot-devtools")https://stackoverflow.com/questions/45016574
复制相似问题