"Welcome To Ashok IT" "Spring Boot and MicroServices" Topic : Spring Boot Internals Date : 16/09/2024 (Session - 25) _____________________________________________________________________________________________________________________________ Last Session ============ 1) We discussed about Spring VS Spring Boot 2) Environmental setup for developing Spring Boot Application 3) Different Ways for Creating the Spring Boot Application * Spring Intializer WebSite * Creating the Project using STS IDE(Spring Starter Project) * Importing the Project either in STS IDE/Intellij IDE. 4) Understanding about spring Boot Application Structure * default configuration file in spring boot application i.e.,application.properties >>>> src/main/resources * pom.xml >>>>>> Spring-boot-dependencies(Parent Project) ^ | Spring-boot-starter-parent(Parent Project) ^ | Our Spring Boot Project(Child Project) * Default Starter in the Spring Boot Application i.e.,spring-boot-starter NOTE ===== 1) If we don't add any starter selection during project creation will get the above default starter and by using that starter we can easily work with Spring Features in Spring Boot Development. 2) If we add any web Starter during the spring boot project creation will not get the above default starter Today Session ============= Application.java (Main Class) ============================= package com.ashokit; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } * Every Spring Boot Application execution will starts from Main method of Java Program * Inside the Main method we have below statement SpringApplication.run(Application.class, args); * run(-,-) is static method from SpringApplication Class and return type of the statement is "ConfigurableApplicationContext" Object i.e.,Spring Container Object. * ConfigurableApplicationContext(CI) is an child interface of ApplicationContext(I). * Inside run(-,-) lot of things doing by the Spring boot application. 1) StopWatch Got Started 2) Preparing Environment Object, If there is no active profile spring boot will fallback to "default" profile and this profile information will available in environment object. 3) Printing Banner in Console >>>> If Banner mode is off, It won't print the banner in the console If Banner mode is log, It will log the banner into log file If we don't set any banner mode, It will print the banner in console. 4) Creating ApplicationContext Container Object based on below starter respective Spring Container got Activated * Spring-boot-starter >>>> DefaultApplicationContextFactory >>>>>> AnnotationConfigApplicationContext * Spring-boot-starter-web >>> AnnotationConfigServletWebServerApplicationContext * Spring-boot-starter-webflux >>>> AnnotationConfigReactiveWebServerApplicationContext 5) Prepare and Refreshing the Context Object 6) Executing & Starting Listeners 7) Executing & Calling Runners. @SpringBootApplication ======================= * It is main annotation for every Spring Boot Application. * It is used to simplify the configuration and bootstrapping of Spring-based applications. * The annotation combines three commonly used annotations: @SpringBootConfiguration, @ComponentScan, @EnableAutoConfiguration. @SpringBootConfiguration ======================== * It is specialized form of the @Configuration annotation specific to SpringBoot Application. * Indicates that the class is a configuration class, providing bean definitions and other Spring configurations. It allows you to define beans and their dependencies explicitly. NOTE ==== @Configuration is an Parent Annotation @SpringBootConfiguration is an Child Annotation * In Spring boot Application we can represent configuration class with help of either any one of above two annotations. @ComponentScan ============== * Scans the specified packages and automatically detects and registers beans within those packages. * It enables component scanning and auto-detection of Spring components, such as controllers, services, repositories, and other beans. @EnableAutoConfiguration ========================= * Enables Spring Boot's auto-configuration mechanism. It automatically configures various Spring components and third-party libraries based on the classpath dependencies and the defined configurations. This reduces the manual configuration required to set up a Spring application.