Spring Boot

44. What is Spring Boot? 
Spring Boot makes creating production-grade applications and services powered by the Spring Framework absolutely easy.
Spring Boot with its opinionated view of the Spring platform enables new and existing users to
quickly get up and running Spring applications quickly. 
Spring Boot provides a range of non-functional features, such as embedded servers, security, metrics, health checks, and
externalized configuration that are common to large classes of projects. In addition, Spring Boot favours
convention over configuration. Therefore, you can develop the application without worrying about any
XML configuration. 
45. Why will you use Spring Boot in your application? 
Spring-based applications have a lot of configurations. For example, if you use Spring MVC,
you need to add configurations, such as component scan, dispatcher servlet, view resolver,
and Web JARs. 

Spring Boot looks at only two things. One, the JARs available on the classpath. Second, the existing
configuration of the application. 
Based on these, Spring Boot provides basic configuration needed to configure the application.
This is called Auto Configuration. Spring Boot makes it easier for you to create Spring application. 
For example, consider that you want to create a Spring Boot application with ActiveMQ
as the messaging service. You add the artifactId as spring–Boot–starter– activemq in your
Maven POM, and Spring Boot will take all the defaults and create an application with ActiveMQ
configured. If you don’t want to use the inbuilt ActiveMQ, you can simply override
spring.activemq.broker-url in your application.properties to use an external one. 

46. List few advantages and disadvantages of Spring Boot. 
Some advantages of Spring Boot are: 
Provides a lot of default configurations to get up and running Spring applications faster 
Comes with embedded Tomcat, Jetty, and Undertow servlet containers, which avoids JAR
deployments. 
Reduces boilerplate code 
Increases productivity as you can create Spring application quickly 
Provides a lot of maven integrated starter projects. You don’t have the problem of version mismatch 
Enables quickly creating a sample project using spring Boot initializer 
Some disadvantages of Spring Boot are: 
If you are new to Spring and want to learn how the dependency injection, AOP programming,
and proxies work, starting with Spring Boot is not a good choice. Spring Boot hides most of these
details from you. 
Converting your old Spring application to Spring Boot application may not be straightforward
and can be time-consuming. 
Spring Boot, with the unused dependencies, may increase the deployment binary size unnecessarily. 
47. What is a Spring Boot starter POM? 
Spring Boot starters reduce the number of dependencies that need to be manually added to an
application. The starter POM contains a lot of dependencies to get an application up and running
quickly. They are convenient dependency descriptors that can be added to your application’s
Maven POM. For example, if you are developing an application that uses Spring Batch for
batch processing, you just have to include spring-boot-starter-batch that will import all the
required dependencies. 
48. What is Actuator in Spring Boot? 
Spring Boot actuator is a subproject of Spring Boot used to access the current state of running the
application in the production environment. Actuators are mainly used to expose different types of
information about the running application, such as health, metrics, info, dump, and env.
You can simply use the restful Web services endpoints provided by Spring Boot actuator and check
various metrics. 
49. What is DevTools in Spring Boot? 
Spring Boot comes with DevTools to increase the productivity of developer. With Spring Boot DevTools,
you as a programmer, don’t need to restart your application for each small changes made to the
application. You just need to reload the changes. Spring DevTools thus avoids the pain of
redeploying application every time you make any change. This module is disabled in the production
environment. 
50. Explain CommandLineRunner in Spring Boot.
How does it differ from ApplicationRunner? 
In Spring Boot application you can execute any required task just before Spring Boot finishes its start-up.
To do so, you need to create Spring bean using CommandLineRunner or ApplicationRunner interface
and Spring Boot will automatically detect them. Both the interfaces have a run() method that needs
to be overridden in implementing classes. You also need to make the class as a bean by using a
Spring stereotype such as @Component. The run() method of bothCommandLineRunner and
ApplicationRunner are executed just before Spring application finishes its start-up.
CommandLineRunner and ApplicationRunner serve the same purpose.
The difference is that the run() method ofCommandLineRunner accepts an array of String as an
argument while the run() method of ApplicationRunneraccepts Spring ApplicationArguments as an argument. The arguments which you pass to main() method while starting Spring Boot, can be accessed in the run()method of both CommandLineRunner and ApplicationRunner implementation classes. You can also create more than one CommandLineRunner and ApplicationRunner beans. To execute them in an order, you can use the @Orderannotation or Ordered interface. 

Comments

Popular posts from this blog

Spring Annotations

Spring Data Access

Spring Model View Controller (MVC)