使用Spring Boot开发人员工具时IntelliJ无法启动Spring Boot/Gradle应用程序 [英] IntelliJ fails to start Spring Boot/Gradle application when using Spring Boot developer tools

查看:295
本文介绍了使用Spring Boot开发人员工具时IntelliJ无法启动Spring Boot/Gradle应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序,一旦我将Spring Boot开发人员工具添加到Gradle构建中,就无法在IntelliJ 2017.1.5中启动:

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")
}

在没有spring-boot-devtools的情况下一切都很好,一旦我添加它们,启动应用程序(在IntelliJ中刷新Gradle项目之后)就会失败,并显示NoClassDefFoundError:

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

我非常确定这是一个IntelliJ问题,因为在启用了Spring Boot开发人员工具的情况下,同一应用程序在Eclipse中运行良好.

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?

推荐答案

我能够通过将对spring-boot-devtools的依赖项更改为:

I was able to resolve this problem by changing the dependency to the spring-boot-devtools to:

runtime("org.springframework.boot:spring-boot-devtools")

代替

optional("org.springframework.boot:spring-boot-devtools")

这篇关于使用Spring Boot开发人员工具时IntelliJ无法启动Spring Boot/Gradle应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆