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 onSpring Boot AutoConfigurator
, so theSpring Boot Stater
will triggersSpring Boot AutiConfigurator
automatically.
@SpringBootApplication And SpringApplication Class#
- In Spring Boot project, we usually see a main class which uses
@SpringBootApplication
andSpringApplication class
as below
Application.java | |
---|---|
1 2 3 4 5 6 7 8 9 10 |
|
- 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 theApplicationContext
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.