springBoot启动输出三行日志控制台自动停止
在https://start.spring.io/(官网)快速创建的springBoot工程,导入到myeclipse中后,启动后自动结束了。
pom.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion >4.0.0</ modelVersion > < groupId >net.xiaof</ groupId > < artifactId >springboot_day01</ artifactId > < version >0.0.1-SNAPSHOT</ version > < packaging >war</ packaging > < name >springboot_day01</ name > < description >springboot_day01 project for Spring Boot</ description > < parent > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-parent</ artifactId > < version >2.0.1.RELEASE</ version > < relativePath /> <!-- lookup parent from repository --> </ parent > < properties > < project.build.sourceEncoding >UTF-8</ project.build.sourceEncoding > < project.reporting.outputEncoding >UTF-8</ project.reporting.outputEncoding > < java.version >1.8</ java.version > </ properties > < dependencies > < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-web</ artifactId > </ dependency > < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-test</ artifactId > < scope >test</ scope > </ dependency > </ dependencies > < build > < plugins > < plugin > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-maven-plugin</ artifactId > </ plugin > </ plugins > </ build > </ project > |
注:此版本为spring-boot 2.2.2。
启动类StartApplication.java:
1
2
3
4
5
6
7
8
9
10
11
12
|
package net.xiaof.boot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class StartApplication { public static void main(String[] args) { SpringApplication.run(StartApplication. class , args); System.out.println( "===================================================================" ); System.out.println( "(◕ˇ∀ˇ◕) springboot started " ); System.out.println( "===================================================================" ); } } |
启动console如下:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.1.RELEASE)2019-12-17 22:55:44.874 INFO 13248 --- [ main] net.xiaof.boot.StartApplication : Starting StartApplication on XIAOHU-WIN10 with PID 13248 (D:\MyEclipse_2017_workspaces\springboot_day01\target\classes started by XIAO in D:\MyEclipse_2017_workspaces\springboot_day01)
2019-12-17 22:55:44.876 INFO 13248 --- [ main] net.xiaof.boot.StartApplication : No active profile set, falling back to default profiles: default
2019-12-17 22:55:47.117 INFO 13248 --- [ main] net.xiaof.boot.StartApplication : Started StartApplication in 2.479 seconds (JVM running for 2.869)
然后Console自动停止了。
解决方法:
建议降低版本,更换为spring-boot 2.0.1。
SpringBoot启动项目后自动关闭,日志打印"Stopping Service"
问题描述:
Java -jar jar包,启动springboot项目,在还没启动完成,日志打印出“Stopping Service”,查看jar进程存在,但访问服务不通,日志无报错。
问题排查:
尝试了各种方式,重新打包,修改tomcat为外部tomcat,修改端口等等都不起作用,依然存在问题。
后来猜测报错了,只是因为日志没有打印出来,又去修改日志级别及其他配置,发现依然看不到问题。
后来尝试修改springboot的启动main方法,
原(无报错日志):
1
2
3
|
public static void main(String[] args) { SpringApplication.run(TestApp. class , args); } |
修改后(无报错日志):
1
2
3
4
5
6
7
|
public static void main(String[] args) { Try{ SpringApplication.run(TestApp. class , args); } catch (Exception e){ e.printStackTrace(); } } |
最终修改(有报错日志):
1
2
3
4
5
6
7
|
public static void main(String[] args) { Try{ SpringApplication.run(TestApp. class , args); } catch (Exception e){ LOGGER.error(“启动报错”,e); } } |
问题分析:
SpringBoot 启动main方法要自己tryCatch一下,打印日志,建议最好使用Logger去输出日志,尽量不要输出到控制台,因为很多公司日志配置不让输出到控制台,故有问题的时候也不会有日志。
能看到报错日志,那么问题排查就很简单了。
(最终是因为MQ配置有问题导致启动报错)
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/hu1010037197/article/details/103589447