解决Spring Boot启动后直接退出的异常

解决Spring Boot启动后直接退出的异常

2020-01-31 11:55:41发布 浏览数:5583
概述:解决Spring Boot启动后直接退出的异常


问题描述

启动Spring Boot之后直接退出,console的输出日志如下:

  .   ____          _            __ _ _

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  '  |____| .__|_| |_|_| |_\__, | / / / /

 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::        (v2.2.4.RELEASE)



2020-01-27 15:43:40.004  WARN 635 --- [           main] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 5005 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).

2020-01-27 15:43:45.012  INFO 635 --- [           main] c.z.s.SpringbootLearningApplication      : Starting SpringbootLearningApplication on Yitian-MacBook-Pro.local with PID 635 (/Users/yitian/Documents/IDEAWorkspaces/LocalProjects/springboot-learning/target/classes started by yitian in /Users/yitian/Documents/IDEAWorkspaces/LocalProjects/springboot-learning)

2020-01-27 15:43:45.013  INFO 635 --- [           main] c.z.s.SpringbootLearningApplication      : No active profile set, falling back to default profiles: default

2020-01-27 15:43:45.616  INFO 635 --- [           main] c.z.s.SpringbootLearningApplication      : Started SpringbootLearningApplication in 15.855 seconds (JVM running for 16.14)

Application start done!



Process finished with exit code 0

问题解决

1. 首先尝试使用try..catch来捕获启动时的异常,结果发现并没有异常产生,还是会启动之后退出,加入的try...catch代码如下:

    public static void main(String[] args) {

        try {

            SpringApplication.run(SpringbootLearningApplication.class, args);

            System.out.println("Application start done!");

        } catch (Exception e) {

            logger.error(e.getMessage());

        }

    }

2. 通过查找资料,发现是maven pom.xml中的配置问题,将其中如下的provided项注释掉既可以解决这个问题:

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

<!--            <scope>provided</scope>-->

        </dependency>

重新启动后,Spring Boot可以正常启动:

  .   ____          _            __ _ _

 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

  '  |____| .__|_| |_|_| |_\__, | / / / /

 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::        (v2.2.4.RELEASE)

 

2020-01-27 15:53:40.041  WARN 748 --- [           main] o.s.boot.StartupInfoLogger               : InetAddress.getLocalHost().getHostName() took 5003 milliseconds to respond. Please verify your network configuration (macOS machines may need to add entries to /etc/hosts).

2020-01-27 15:53:45.048  INFO 748 --- [           main] c.z.s.SpringbootLearningApplication      : Starting SpringbootLearningApplication on Yitian-MacBook-Pro.local with PID 748 (/Users/yitian/Documents/IDEAWorkspaces/LocalProjects/springboot-learning/target/classes started by yitian in /Users/yitian/Documents/IDEAWorkspaces/LocalProjects/springboot-learning)

2020-01-27 15:53:45.050  INFO 748 --- [           main] c.z.s.SpringbootLearningApplication      : No active profile set, falling back to default profiles: default

2020-01-27 15:53:45.774  INFO 748 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)

2020-01-27 15:53:45.782  INFO 748 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

2020-01-27 15:53:45.782  INFO 748 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.30]

2020-01-27 15:53:45.832  INFO 748 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

2020-01-27 15:53:45.833  INFO 748 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 747 ms

2020-01-27 15:53:45.981  INFO 748 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'

2020-01-27 15:53:46.104  INFO 748 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''

2020-01-27 15:53:46.106  INFO 748 --- [           main] c.z.s.SpringbootLearningApplication      : Started SpringbootLearningApplication in 16.314 seconds (JVM running for 16.605)

Application start done!

 

请先
登录
后评论
0 条评论
暂时没有评论