AddThis

Sunday, 19 August 2018

Spring Boot Initializer

SpringApplication:

The SpringApplication class provides a convenient way to bootstrap a Spring application that will be started from a main() method. In many situations you can just delegate to the static
SpringApplication.run method:
  • SpringApplication is one of the Spring Boot API classes.
  • SpringApplication class is used to bootstrap a Spring application that will be started from a main() method
package com.programingsoeasy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MySpringBootAppApplication {

 public static void main(String[] args) {
  SpringApplication.run(MySpringBootAppApplication.class, args);
 }
}

MySpringBootAppApplication class is annotated with @SpringBootApplication annotation.
@SpringBootApplication does the following things:
  • Because of @Configuration annotation, It scans for @Bean methods to create beans.
  • Because of @ComponentScan annotation, It does component scanning (Components means Beans annotated with @Component,@Service,@Repository,@Controller etc).
  • Because of @EnableAutoConfiguration annotation, It triggers Spring Boot Auto-Configuration.
When we run MySpringBootAppApplication class main() method, it make a calls to “SpringApplication.run()” method. Then this call done following things

  • This call is used to create “AnnotationConfigEmbeddedWebApplicationContext”.
  • This “AnnotationConfigEmbeddedWebApplicationContext” instance is used to create an instance of “TomcatEmbeddedServletContainerFactory” class.
  • This “TomcatEmbeddedServletContainerFactory” is used to create an instance of “TomcatEmbeddedServletContainer” class.
  • TomcatEmbeddedServletContainer” instance starts a Tomcat Container at default port number: 8080 and deploys our Spring Boot WebApplication.

No comments:

Post a Comment

Solving real time queries using java 8 features stream api with examples

package com.pse; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java...