Spring Boot
What is Spring Boot?
Spring Boot is basically an extension of
the Spring framework which eliminates
the boilerplate configurations required
for setting up a Spring application.
Features of Spring Boot
• Create stand-alone Spring applications with
• Embeded Tomcat, Jetty or Undertow directly
(no need to deploy WAR files)
• Provide opinionated ‘starter’ dependencies to
simplify your build configuration. Opinionated
in the sense Framework choose
configurations. It will configure basic setup
for you based on some parameters.
• Automatically configure Spring and 3rd party
libraries whenever possible
• Provide production-ready features such as
metrics, health checks and externalized
configuration
• Absolutely no code generation and no
requirement for XML configuration
• It is highly dependent on the starter
templates feature which is very powerful
and works flawlessly.
Spring vs Spring Boot
Spring
Dependency Injection Framework
Manage lifecycle of java classes(beans)
Boiler plate configuration(programmer
writes a lot of code to do minimal task)
Takes time to have a spring application
up and running
Benefits of Spring Boot
Dependency Resolution
Minimum Configuration
Embedded server for testing
Bean auto scan
Health metrics
Standarization for microservices
Cloud support
Adapt and support for 3rd party libraries
In one sentence, Spring Boot is (Spring Framework-XML
Configuration) +Integrated server.
How does it work? How does it know what to
configure?
Spring Boot detects the dependencies available on the
classpath and configures Spring beans accordingly.
There are a number of annotations, examples are
@ConditionalOnClass, @ConditionalOnBean,
@ConditionalOnMissingBean and
@ConditionalOnMissingClass, that allows for applying
conditions to Spring configuration classes or Spring
bean declaration methods in such classes.
Examples:
A Spring bean is to be created only if a certain
dependency is available on the classpath. Use
@ConditionalOnClass and supply a class contained in
the dependency in question.
A Spring bean is to be created only if there is no bean
of a certain type or with a certain name created. Use
There are a number of condition annotations in
Spring Boot each of which can be used to control the
creation of Spring beans. The following is a list of the
condition annotations in Spring Boot (there are more):
Spring Boot will do the following when you
create the application
Classpath Scan
Default configuration setup
Create an appropriate ApplicationContext
instance
Start embedded application server(for web
application)
Let’s see how Spring Boot internally works
Starter POM
META-INF/spring.factories 1.Enable
Disable
Based on @Conditional and @Configuration it
@SpringBootApplication
This is a combination of
@SpringBootConfiguration,@EnableAutoConfi
guration and @ComponentScan
@SpringBootConfiguration
Indicates that a class provides Spring Boot
application @Configuration. Can be used as an
alternative to the Spring’s standard
@Configuration annotation so that
configuration can be found automatically
@EnableAutoConfiguration
This enables the component at runtime.
Spring Boot auto-configuration attempts to
automatically configure your spring application
based on their jar dependencies that you have
For example, in general in Spring MVC, DispatcherServlet and
InternalResourceViewResolver will be configured in web.xml or
we will go with Java Based configuration.
In Spring Boot, DispatcherServlet and
InternalResourceViewResolver are autoconfigured to avoid boiler
plate configuration.
@ComponentScan
This will be used by Spring IOC container to scan the packages
for fetching the bean.
Why we need main method in Spring Boot application
Spring Boot Application executes as a standalone application so a
main method is necessary and it helps to deploy the application
jar in the embedded tomcat.
SpringApplication.run(…) internal flow
Create application context
Check the application type
Register the annotated class beans with the context
Creates an instance of TomcatEmbeddedServletContainer and
adds the context