SpringBoot Application
The way for start application
There are few ways start Spring Boot Application in main method.
- Using static method.
1 | SpringApplication.run(Application.class, args); |
- Using instance (Able to customizing).
1 | SpringApplication app = new SpringApplication(Application.class); |
- using SpringApplicationBuilder.
If want generate hierarchical Application Context, use SpringApplicationBuilder.
1 | new SpringApplicationBuilder() |
Applcation type
Where are few application type.
- SERVLET
Can execute based on Servlet as write below code.
1 | SpringApplication app = new SpringApplication(Application.class); |
- No web
Can execute based on just Java application as write below code.
1 | SpringApplication app = new SpringApplication(Application.class); |
- Spring webflux
Can execute based on Spring webflux as write below code.
1 | SpringApplication app = new SpringApplication(Application.class); |
Argument value
If you try to use an argument value and the value is --bar
, can get this way as like below.
1 |
|
The result like below.
1 | 2020-02-16 14:41:57.272 INFO 2452 --- [ main] me.ewan.ewan.Application : Starting Application on always with PID 2452 (C:\Users\gyun\IdeaProjects\SpringStudy+\build\classes\java\main started by gyun in C:\Users\gyun\IdeaProjects\SpringStudy+) |
Application Listener
Can get be imported at application startup and end point.
- ApplicationStartingEvent (When application starts)
1 |
|
But in this case, ApplicationStartingEvent create more faster than Application Context.
So need additional task that add Listener at Main method.
1 | SpringApplication app = new SpringApplication(Application.class); |
- ApplicationStartedEvent (After application starts)
In this case, ApplicationStartedEvent created later than Application Context, so do not need any additional task.
1 |
|