Skip to content

SpringBoot Starter Introduction#

What Is The SpringBoot Starter?#

  • Spring boot starters is one of the major key features or components of Spring Boot Framework. The main responsibility of Spring boot stater is to combine a group of common or related dependencies into single dependencies.
  • Major advantanges of Spring boot Stater:
  • Spring boot stater reduces defining many dependencies simplify project build dependencies.
  • Spring boot stater simplifies project build dependencies.
  • Ex: To develop a spring WebApplication with Tomcat webserver, we need to add some dependencies and below into Maven's pom.xml file.
    • Spring core jar file.
    • Spring web jar file.
    • Spring web MVC jar file.
    • Servlet jar file.
  • So, if we add "spring-boot-stater-web" jar file dependency to our build file, then spring boot framework will automatically download all required jars and add to our project classpath.
  • As you can see in the image below, Spring Boot Stater has a dependency on Spring Boot AutoConfigurator, so the Spring Boot Stater will triggers Spring Boot AutiConfigurator automatically.

 #zoom

@SpringBootApplication And SpringApplication Class#

  • In Spring Boot project, we usually see a main class which uses @SpringBootApplication and SpringApplication class as below
Application.java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
package com.exception.handler.demo;
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);
    }
}
  • So as we learned above @SpringBootApplication annotation is used to mark a configuration class that declares one or more @Bean methods and also triggers auto-configuration and component scanning. It's same as declaring a class with @Configuration, @EnableAutoConfiguration and @ComponentScan annotations.
  • SpringApplication class is used to bootstrap and launch a spring application from a Java main method. This class automatically create the ApplicationContext from the classpath, scan the configuration classes and launch the application. This class is very helpful in launching Spring MVC or Spring REST application using Spring Boot.

References#