The biggest selling point for spring boot is "open the box and use it," but many people are only in writing @springbootapplication. If you don't know what's going on between the moin method and the start of the container, then many of the problems with the start failure can only be guessed。
Spring boot, what is it
The start-up entry for spring boot is springapplication. Run(). It does two things inside: it creates the springapplication example, and it calls the run() method to start the application. The whole process is very compact, but a large number of automatic assembly and event mechanisms are hidden。
Core source
The core logic of springapplication. Run() is in the springapplication category. It extrapolates the type of application, then creates applicationcontext, and lasts the container。
Public coNfigurableapplicationcontext run
long starttime = system. Nanotime();
default bootstrapcoNo, no, no= createbootstreamcoNtext();
coNo, no, no, no, no. Springapplicatio= get runlistens (args);
listeners. Starring (bootstreamcontext, this. Mainapplicationclass);
try
applicatioI'm sorry, sir== sync, corrected by elderman ==I'm sorry. CoIt's not a bad idea= prepareenviroI don't know what you're talking about. Co{\bord0\shad0\alphah3d}affirmableapplicationcontext co= createapplicatoNcontext();
preparecoNtext. I'm sorry- what's your name? Afterrefresh;
okay, listeners. I'm sorry.
♪ i'm sorry ♪
catch (throwable ex)
handle runfailure;
throw new illegalstateexception;
♪ i'm sorry ♪
♪ i'm sorry ♪
Full process from main to run
A spring boot application started from the main method and the complete process available to the packaging is:
Execute springapplication. Run() infer web application type (servlet/reactive/none) load springapplicationrunlistener preparation enviroNment and command line arguments create applationcontext preparation
Contrast
Spring boot
Heritage spring
Start the portal
Springapplication. Run()
Manual load applicationcontext
Autoassembly
Automatically read mEts-inf/spring. Factors
Manual configuration
Embedded container
Internal tomcat/jetty
External deployment
Start event
Full spring boot life cycle event
Standard spring event
My point
Spring boot's startup process is designed very well. It encapsulates the complex spring start-up process into standard steps and makes expansion simple through incident mechanisms. I usually use spring boot's start timer to locate the time point when i'm running a slow start。
For who? For who? Summary
Spring boot's start-up process remains essentially spring's refresh(), but a layer of automatic assembly, environmental preparation and event release is added outside. If you understand this layer, you can explain why spring boot can run a zero configuration。
Statement: this is a personal source learning note, non-commercial。










