Spring Boot Framework has mainly four major Components.
Spring Boot Starters
Spring Boot AutoConfigurator
Spring Boot CLI
Spring Boot Actuator
Spring Boot Starters is one of the major key features or components of Spring Boot Framework. The main responsibility of Spring Boot Starter is to combine a group of common or related dependencies into single dependencies.
For instance, If we are using traditional Spring framework and we would like to develop a Spring WebApplication with Tomcat WebServer. Then we need to add the following minimal jar dependencies in your Maven’s pom.xml file.
Spring core Jar file(spring-core-xx.jar)
Spring Web Jar file(spring-web-xx.jar)
Spring Web MVC Jar file(spring-webmvc-xx.jar)
Servlet Jar file(servlet-xx.jar)
If we want to add some database stuff, then we need to add database related jars like Spring JDBC jar file, Spring ORM jar files, Spring Transaction Jar file etc.
Spring JDBC Jar file(spring-jdbc-xx.jar)
Spring ORM Jar file(spring-orm-xx.jar)
Spring Transaction Jar file(spring-transaction-xx.jar)
We need to define lot of dependencies in our build files. It is very tedious and cumbersome tasks for a Developer. And also it increases our build file size.
What is the solution to avoid this much dependencies definitions in our build files?
- The solution is Spring Boot Starter component.
Spring Boot Starter component combines all related jars into single jar file so that we can add only jar file dependency to our build files. Instead of adding above 4 jars files to our build file, we need to add one and only one jar file: “spring-boot-starter-web” jar file.
When we add “spring-boot-starter-web” jar file dependency to our build file, then Spring Boot Framework will automatically download all required jars and add to our project classpath.
In the same way, “spring-boot-starter-logging” jar file loads all it’s dependency jars like “jcl-over-slf4j, jul-to-slf4j, log4j-over-slf4j, logback-classic” to our project classpath.
Another important key component of Spring Boot Framework is Spring Boot AutoConfigurator. Traditional Spring Framework requires lots of configurations and for this it uses Either XML Configuration or Annotation Configuration.
The solution to this problem is Spring Boot AutoConfigurator. The main responsibility of Spring Boot AutoConfigurator is to reduce the Spring Configuration.
If we develop Spring applications in Spring Boot, then we don’t need to define single XML configuration and almost no or minimal Annotation configuration. Spring Boot AutoConfigurator component will take care of providing those information.
For instance, if we want to declare a Spring MVC application using Spring IO Platform, then we need to define lot of XML Configuration like views, view resolvers etc. But if we use Spring Boot Framework, then we don’t need to define those XML Configuration. Spring Boot AutoConfigurator will take of this.
If we use “spring-boot-starter-web” jar file in our project build file, then Spring Boot AutoConfigurator will resolve views, view resolvers etc. automatically.
And also Spring Boot reduces defining of Annotation configuration. If we use @SpringBootApplication annotation at class level, then Spring Boot AutoConfigurator will automatically add all required annotations to Java Class Bytecode.
If we go through Spring Boot Documentation, we can find the following definition for @SpringBootApplication. [Includes many other annotations so we need to use this, no need to write many annotations.]
@Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Inherited
@Configuration
@EnableAutoConfiguration
@ComponentScan
Public @interface SpringBootApplication
That is, @SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiration.
Note:
In simple words, Spring Boot Starter reduces build’s dependencies and Spring Boot AutoConfigurator reduces the Spring Configuration.
As we discussed that Spring Boot Starter has a dependency on Spring Boot AutoConfigurator, Spring Boot Starter triggers Spring Boot AutoConfigurator automatically.
We may not require this feature as we are going to develop application in eclipse or spring IDE.
Spring Boot CLI (Command Line Interface) is a Spring Boot software to run and test Spring Boot applications from command prompt.
When we run Spring Boot applications using CLI, then it internally uses Spring Boot Starter and Spring Boot AutoConfigurate components to resolve all dependencies and execute the application.
When we run our Spring Boot Web Application, Spring Boot Actuator automatically provides hostname as “localhost” and default port number as “8080”. We can access this application using “http://localhost:8080/” end point.
We actually use HTTP Request methods like GET and POST to represent Management Endpoints using Spring Boot Actuator.
In simple words it connects our application to some port and it is easily accessible we need not to deploy our application explicitly.