springBoot启动输出三⾏⽇志控制台⾃动停⽌操作springBoot启动输出三⾏⽇志控制台⾃动停⽌
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /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>
&porting.outputEncoding>UTF-8</porting.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:
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 byspringframework和springboot
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⽅法,
原(⽆报错⽇志):
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
修改后(⽆报错⽇志):
public static void main(String[] args) {
Try{
SpringApplication.run(TestApp.class, args);
}catch(Exception e){
e.printStackTrace();
}
}
最终修改(有报错⽇志):
public static void main(String[] args) {
Try{
SpringApplication.run(TestApp.class, args);
}catch(Exception e){
<(“启动报错”,e);
}
}
问题分析:
SpringBoot 启动main⽅法要⾃⼰tryCatch⼀下,打印⽇志,建议最好使⽤Logger去输出⽇志,尽量不要输出到控制台,因为很多公司⽇志配置不让输出到控制台,故有问题的时候也不会有⽇志。
能看到报错⽇志,那么问题排查就很简单了。
(最终是因为MQ配置有问题导致启动报错)
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论