【发布时间】:2018-03-07 19:18:44
【问题描述】:
【问题讨论】:
-
复制/粘贴命令行并在
cmd.exe中运行是否有效? -
这可能是由于 application.properties 文件中的属性/配置不正确而发生的。请重新查看配置并更正错误
标签: tomcat spring-boot intellij-idea
【问题讨论】:
cmd.exe中运行是否有效?
标签: tomcat spring-boot intellij-idea
【讨论】:
我遇到了同样的问题。 Springboot 以代码 1 退出,没有错误。但那是我在不使用 Spring Initializer 的情况下创建项目的时候。
我建议您备份您的代码并使用 Spring Initializer(服务 URL:https://start.spring.io)重新创建项目,这应该可以工作。并且您将能够比较设置差异。
【讨论】:
它非常复杂,因为大多数情况下它可能是由于缺少属性而发生的。在我的情况下, application.properties 中未定义的以下属性导致此问题及其线索较少。希望对你有帮助
由于缺少任何 Bean 或组件中定义的服务器端口或任何其他占位符等属性,都可能导致此问题。验证所有属性和占位符。
@Value(value = "${resource.path.accountNumbers}")
private Resource accountNumbers;
application.properties--verify all properties/placeholders
resource.path.accountNumbers=classpath:accountNumbers.properties
【讨论】:
您必须将logging.level.root 设置为DEBUG 并阅读相关日志才能发现问题。
如果您的应用使用 application.yml 文件,请在开头或结尾添加(或编辑):
logging:
level:
root: DEBUG
如果您的应用使用application.properties,请在以下行添加(或编辑):
logging.level.root: DEBUG
例如,我的应用程序使用了一个未定义的属性,并且没有在常见日志中显示问题,启用调试级别日志记录后,我在日志中得到以下行:
Could not find key 'app.services.account.service' in any property source
【讨论】:
尝试通过在 main 方法中放置“try-catch”块、围绕“run”方法调用并在“catch”中打印堆栈跟踪来获取堆栈跟踪,如下所示。
public static void main(String[] args) {
try {
SpringApplication.run(MyApplication.class, args);
} catch (Exception e) {
e.printStackTrace();
}
}
【讨论】:
Throwable 而不是Exception 才能捕获Errors。
application.yml 的非法语法(我错过了 logging.pattern.console 配置中的 } 字符)。
遇到同样的问题。
通过指定父 Spring Boot Starter 项目修复。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath />
</parent>
【讨论】:
在这种情况下可能不完全正确,但缺少日志也可能是由于 logback.xml 文件中缺少配置文件配置而导致的。
【讨论】:
这个命令为我完成了这项工作:
mvn idea:idea
【讨论】: