What happens when a Spring Booot Start up ? | Internal Flow of Spring boot project | Part 4

preview_player
Показать описание
In this session - we will discuss the internal flow of spring boot - what happens when a spring Boot Starts up.
How does internally this work?

- Spring does not generate any code automatically and not using any xml configuration file .
- spring uses internally pragmatically configuration done by spring boot developer that are provided by jar.

Based on @Conditional and @Configuration :
It will serach for the DataSource bean if it is available then only it will enable JpaRepositoriesAutoConfiguration . So this we need to define DataSource related properties into our property file.

It will serach for the JpaRepository class if it is available then only it will enable JpaRepositoriesAutoConfiguration .

If all conditions are true then only it will enable JpaRepositoriesAutoConfiguration class.

If all the conditions are satisfied then only spring will enable to the component.

Summary:-
When Spring Boot boots up:
It tries to read in .properties from 17 hard-coded locations.
It has an enhanced concept of @Conditionals, compared to plain Spring.

Now it turn to Analyze the Tomcat AutoConfiguration
How can Spring Boot boot up an embedded Tomcat server by default?
It needs to take Spring WebMVC’s DispatcherServlet and register it with Tomcat, to make your @RestControllers with their @GetMappings and @PostMappings work.
It needs to start your embedded Tomcat server (and therefore your DispatcherServlet).
Basically, spring boot supports three embedded servers:- Tomcat (default), Jetty and Undertow.

High Level Flow Of Spring Boot And How run Method works :
From the run method, the main application context is kicked off -
which in turn searches for the classes annotated with @Configuration,
initializes all the declared beans in those configuration classes,
and based upon the scope of those beans,
stores those beans in JVM, specifically in a space inside JVM which is known as IOC container.
After the creation of all the beans, automatically configures the dispatcher servlet and registers the default handler mappings, messageConverts, and all other basic things.
What is the internal flow of run() :
Create application context
Check Application Type
Register the annotated class beans with the context
Creates an instance of TomcatEmbeddedServletContainer : and adds the context. Used to deploy our jar automatically.

#springboot #spring
Рекомендации по теме
join shbcf.ru