Spring Boot 应用程序无法以类路径启动:[]

Posted

技术标签:

【中文标题】Spring Boot 应用程序无法以类路径启动:[]【英文标题】:Spring Boot Application failed to start with classpath: [] 【发布时间】:2018-03-17 21:41:08 【问题描述】:

我使用jHipster 生成了一个 Spring Boot 应用程序,添加了我之前项目(非 jhipster 项目)中的一些代码,并尝试使用 IDEA 运行它。首先,我收到类似于this 的错误消息,说“命令行太长..”(我运行的是 Windows 10 x64)。我点击了启用,但随后出现这样的错误。:

"C:\Program Files\Java\jdk1.8.0_144\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:51351,suspend=y,server=n -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=51350 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath C:\Users\User\AppData\Local\Temp\classpath.jar com.test.pc.TestPartsComposerApp
Connected to the target VM, address: '127.0.0.1:51351', transport: 'socket'
The Class-Path manifest attribute in C:\Users\User\AppData\Local\Temp\classpath.jar referenced one or more files that do not exist: .... Extremely long list of jars
07:48:56.779 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
07:48:56.779 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
07:48:56.779 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : []

07:48:57.570 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: []

在我尝试使用 ./mvnw:

The Class-Path manifest attribute in C:\Users\User\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-impl-2.2.3-1.jar referenced one or more files that do not exist: C:\Users\User\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb-api.jar,C:\Users\User\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\activation.jar,C:\Users\User\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jsr173_1.0_api.jar,C:\Users\User\.m2\repository\com\sun\xml\bind\jaxb-impl\2.2.3-1\jaxb1-impl.jar
The Class-Path manifest attribute in C:\Users\User\.m2\repository\org\liquibase\liquibase-core\3.5.3\liquibase-core-3.5.3.jar referenced one or more files that do not exist: C:\Users\User\.m2\repository\org\liquibase\liquibase-core\3.5.3\lib\snakeyaml-1.13.jar
07:53:54.295 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
07:53:54.295 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
07:53:54.295 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/workspace/jh-fpc/TestPartsComposer/target/classes/]
07:53:55.295 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/C:/workspace/jh-fpc/TestPartsComposer/target/classes/]

我发布了我的pom.xml here。

我创建了一个全新的项目,并开始一一添加我拥有的 maven 依赖项,并在每一步之后运行该项目。当我将 BOTH spring-batch 和 guava 添加到 pom 时,会出现类路径的问题。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>$guava-core.version</version>
</dependency>

【问题讨论】:

您是否尝试过强制 IDEA 重新读取所有 maven 依赖项***.com/q/9980869/1032167 或清理并重建? @varren 我什至删除了我的 .m2 目录,让 maven 重新下载所有内容。但是我只是添加了问题的主要原因,不知道为什么会导致它。 我对 liquibase 有同样的问题,但它没有阻止应用程序启动,您可以忽略该消息(错误liquibase.jira.com/browse/CORE-3046)您尝试过mvn clean install 然后mvn spring-boot:run 吗? @Paizo 我确实试过了,但我的问题不在于 liquibase,maven 甚至无法编译它。 【参考方案1】:

我在 jHipster 应用程序中遇到了同样的问题,并带有相同的错误消息,对我来说,根本原因是 application-dev.yml 中的 spring 邮件设置的格式(缩进)错误。我只是从另一个项目中复制/粘贴了设置,IntelliJ 将它们缩进了一些与原始代码不同的缩进,因此它们无法解析。

那些“清单属性”的东西每次启动应用程序时都会出现,但至少对我来说它们与真正的问题无关。希望这有助于找到原因的根源!干杯,

【讨论】:

我检查了我的application-*.yml 文件,发现它由于tab 字符而无法启动。我插入了 4 个空格,它又可以工作了。 这可能是真正的答案,但我无法确认,因为我不再遇到这个问题。 我遇到过一个与spring非常相似的问题。经过数小时的调试,它归结为一个错误的 yml。在第一种情况下是因为缩进,在另一种情况下是因为我多次定义了同一个字段。注意有多个 yml 文件的设置,例如,在 Tomcat 中处理多个 yml【参考方案2】:

此错误消息由 ClasspathLoggingApplicationListener#onApplicationEvent

但它并没有输出错误的真正原因。

所以,你应该在调试模式下启动你的应用程序,并在这一行添加一个断点,然后你可以检查event.exception,找出真正的错误是什么。

这个问题浪费了我大约 30 分钟......希望这个答案可以节省一些时间

【讨论】:

我无法轻松设置断点,因此我将 ClasspathLoggingApplicationListener 的源代码复制到我的应用程序中的 org.springframework.boot.context.logging 包中。在 ClasspathLoggingApplicationListener 的 onApplicationEvent 方法中,我添加了将异常打印到标准输出。现在我在日志中看到了导致异常的原因。我知道这是一个疯狂的解决方案。【参考方案3】:

同样的问题,我只是忘记在 application.properties 中设置 spring.profiles.active 并且我有多个 application-*.properties

【讨论】:

【参考方案4】:

移除依赖spring-boot-devtools

【讨论】:

【参考方案5】:

我在使用 JHipster(6.4.1) 应用程序时遇到了同样的问题,根据 @koni123 的建议,我发现我不小心复制了 logback-spring.xml 中的 XML 声明。

修复问题后,我可以看到启动时仍会打印清单警告,所以这只是一个红鲱鱼。

【讨论】:

【参考方案6】:

我在 Spring 中也遇到过这个问题,似乎根本原因是我的 pom 中存在一个冲突的 SLF4J 依赖项,与 Spring 本地使用的版本不同。

【讨论】:

【参考方案7】:

我在jhipster @4.10.2 遇到了同样的问题,我在这里得到了解决方案

正如@koni123 正确地说这与application-dev.yml 有关,当我将此文件与以前的文件版本进行比较时,发现“spring.jpa.hibernate.format_sql: true”给了我问题。一旦我从 application-dev.yml 中删除它,它就解决了我的问题。希望这会有所帮助。

【讨论】:

【参考方案8】:

确保您的记录器中的 CONSOLE 附加程序处于活动状态。这将告诉您 Eclipse 控制台中真正的问题是什么

<root level="info">
        <appender-ref ref="CONSOLE" /> 
        <appender-ref ref="FILE" />
</root>

【讨论】:

以上是关于Spring Boot 应用程序无法以类路径启动:[]的主要内容,如果未能解决你的问题,请参考以下文章

无法启动 Spring Boot 应用程序

无法启动 Spring Boot 应用程序

Spring boot 无法启动 HSQLDB

无法在 IntelliJ Idea 中启动 spring-boot 应用程序

带有休眠应用程序的 Spring Boot 无法启动

Spring Boot无法使用intellij idea启动应用程序