springboot特点之SpringApplication

SpringApplication类提供了一个方便的方式启动,由main()方法启动。很多情形你可以委托给static 的 SpringApplication.run 比如下面这样:
@SpringBootApplication
public class MyApplication {
 public static void main(String[] args) {
 SpringApplication.run(MyApplication.class, args);
 }
}

当你的项目启动你将在控制台上看到如下日志 

  . ____ _ __ _ _
 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  ' |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot :: v2.5.5
2021-02-03 10:33:25.224 INFO 17321 --- [ main]
o.s.b.d.s.s.SpringAppplicationExample : Starting SpringAppplicationExample using
Java 1.8.0_232 on mycomputer with PID 17321 (/apps/myjar.jar started by pwebb)
2021-02-03 10:33:25.226 INFO 17900 --- [ main]
o.s.b.d.s.s.SpringAppplicationExample : No active profile set, falling back to
default profiles: default
2021-02-03 10:33:26.046 INFO 17321 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080
(http)
2021-02-03 10:33:26.054 INFO 17900 --- [ main]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-02-03 10:33:26.055 INFO 17900 --- [ main]
org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache
Tomcat/9.0.41]
2021-02-03 10:33:26.097 INFO 17900 --- [ main]
o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded
WebApplicationContext
2021-02-03 10:33:26.097 INFO 17900 --- [ main]
w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization
completed in 821 ms
2021-02-03 10:33:26.144 INFO 17900 --- [ main]
s.tomcat.SampleTomcatApplication : ServletContext initialized
2021-02-03 10:33:26.376 INFO 17900 --- [ main]
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with
context path ''
2021-02-03 10:33:26.384 INFO 17900 --- [ main]
o.s.b.d.s.s.SpringAppplicationExample : Started SampleTomcatApplication in 1.514
seconds (JVM running for 1.823)

默认的日志级别是INFO,包括一些相关的启动详情,比如启动程序的用户。如果你想改变日志级别,请在Log Levels更改。如果你想关掉,配置这个属性spring.main.log-startup-info 为false。

另外你也可以重写SpringApplication 子类的logStartupInfo(boolean)方法。

Startup Failure启动失败

如果你的程序启动失败,被注册的 FailureAnalyzers 获得一次提供专用的错误信息,和具体修复的动作的机会。下面这个例子,错误描述:表明8080端口已经被占用,恢复动作:定义和停止监听8080这个端口或者重新配置另外一个端口。
***************************
APPLICATION FAILED TO START
***************************
Description:
Embedded servlet container failed to start. Port 8080 was already in use.
Action:
Identify and stop the process that's listening on port 8080 or configure this
application to listen on another port.

Lazy Initialization懒加载

sprigApplication允许程序懒加载。如下配置即可实现

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值