SpringBoot启动后直接退出Process finished with exit code 1

问题描述

出现这个问题时,控制台没有任何输出,进程直接退出Process finished with exit code 1

问题解决

尝试加了一行打印语句
System.out.println("SpringBoot Start....");

结果是可以打印出来的:

SpringBoot Start....
Process finished with exit code 1

此时突然想到,那程序入口没问题,就是下一行的问题了。

try {
  SpringApplication.run(Application.class, args);
}catch(Exception e) {
  e.printStackTrace();
}

结果是依然没有任何输出。但是作为踩坑无数的Java程序员,我们知道Exception还不是最顶级的异常类,于是换成Throwable

try {
  SpringApplication.run(Application.class, args);
}catch(Throwable e) {
  e.printStackTrace();
}

这样打印出来真正的错误了,是一个 ClassDefNotFoundError

解决方案

出现这种情况,首先就要排除依赖冲突的问题,例如可以搜一下具体的这个Class。
将pom文件修改一下,排除某些依赖,然后多reimport一下项目,在Project Structure中,多检查检查Project Library,看看是否有不正常的版本。

例如在实际项目中,我用到的是最新的Spring 5.x,但是在Project Library中看到了 Spring 4.3.6的依赖。

结果仔细查发现两个问题:

  1. Apache Dubbo 2.7.8的依赖是 Spring 4.3.6。
  2. 即使排除了Apache Dubbo 2.7.8,因为IDEA可能有缓存,导致需要多次reimport才能起效。

最后把依赖重新整理一下,该exclude掉的exclude了。

最后就可以直接run了。

原文地址:https://www.cnblogs.com/slankka/p/13590451.html