Top Spring Boot Interview Questions
1. What is Spring Boot?
- Spring is a Framework to build Java based applications
- Spring boot is a solution to make use of Spring Framework more easier
- Applications built using Spring Framework involves making a lot of configurations and is time consuming to start developing.
- Spring boot makes this easier by using default configurations that most developers expect.
- In simple terms, Spring boot is a solution for Spring framework providing opinionated defaults for production grade applications that can run standalone.
2. How does spring boot help easier application development?
- Springboot applications can run standalone. You dont need deploy on it a server since it has an embedded tomcat server by default
- Springboot enables creating production grade applications faster
- Springboot chooses the APIs to use for a particular purpose by default unless you provide specific vconfigurations.
- No XML configuration
- No code generation
3. Can you provide some examples of the default choices and auto configurations done by Spring boot?
- Spring boot chooses the defaults based on the starters and other dependencies you choose
- If you write web application, embedded tomcat server is the default and 8080 is default port
- If you use JSON, Jackson is the preferred and default API
- If you use JPA, Hibernate is the default API
- If you use an embedded Database like H2, HSQL and Derby, Spring boot does auto-configuration of connection URLs.
4. What are the ways to create a spring boot project?
- Using http://start.spring.io - Very simple and easy to use. Once you download, simply extract the zip file and your sample project is ready. You can start working on it.
- Create it from scratch using Spingboot CLI - if you like using command line style
- Create it from scratch using IDE - eclipse or netbeans or Java IDEs you prefer.
5. What are steps involved to create a spring boot project?
- Create pom.xml
- Create a class with main method annotated with @SpringBootApplication
- Next set of steps involved depend on the type of application to be built
- if you want to write a REST service, annotate it with @RestController
- if you want to write a MVC application, annotate it with @EnableWebMvc
- if you want to write a Eureka Server, annotate it with @EnableEurekaServer
6. What is spring-boot-starter-parent?
- In Most cases, we use pom.xml in such a way that it inherits parent Maven POM named the spring-boot-starter-parent. spring-boot-starter-parent is a special starter project
- It provides maven defaults.
- It manages spring boot dependencies and plugins like downloading jar files.
- It supports a big list of plugins which include
- maven-compiler-plugin, maven-failsafe-plugin, maven-resources-plugin,
- exec-maven-plugin, git-commit-id-plugin, spring-boot-maven-plugin,
- maven-shade-plugin, maven-jar-plugin, maven-surefire-plugin, maven-war-plugin.
7. What are spring boot "starters"?
- "starters" are springboot provided.
- starters are maven POM xml or gradle groovy files which have pre-configured spring dependencies.
- These starters can be included as a dependency in other starter files or maven or gradle files.
- If you are using Maven, Dependencies can be specified as names of jar, war, ear, rar, zip or pom xml or starter pom xml files.
- In Maven, Plugins are used to perform actions like compile code, test code and many other actions.
- To summarize, starter can specify jar names as well as other starter POM xml files as dependencies.
- As a result, jar files are added to the classpath when maven core or maven plugins perform the actions configured.
8. What does spring boot spring-boot-starter-web do?
- spring-boot-starter-web is a pom.xml which includes other starters and jar files
- starters that are part of spring-boot-starter-web:
- jar files:
9. Name 20 starter packages you have used?
- spring-boot-starter-data-rest - Spring Data REST combines the features of Spring HATEOAS and Spring Data JPA
- spring-boot-starter-amqp - RabbitMQ is the default AMQP
10. What does @SpringbootApplication mean?@SpringbootApplication is equivalent of using 3 annotations - @Configuration, @EnableAutoConfiguration and @ComponentScan
11. What is the advantage of using @SpringbootApplication?
- Enables the scanning of dependencies in the same class
- Enables the auto configuration of the required dependencies
- Allows to customize the configuration of your application
12. What does @EnableAutoConfiguration mean?Enables the auto configuration of the required dependencies. Based on the Jar files in the classpath, Spring boot makes a guess and configures spring beans. For example, if you have spring-boot-starter-web in your pom.xml, embedded tomcat jar is automatically added to classpath
13. What does @Configuration mean?Allows to customize the configuration of your application
14. What does @ComponentScan mean?Enables the scanning of dependencies in the same class
15. What are microservices?Microservices is an architecture style. An application is designed as a group of loosely coupled microservices.
Microservices differentiates itself from Monolith Applications and SOA.
Microservices can be designed either by breaking an existing monolith application or creating new microservices.
Monolith applications are developed and deployed as single application.
If they have too many components, then those can be designed as microservices if the following problems need to be solved:
- Each component requires to be deployed independently
- Each component requires to be developed, maintained and tested independently or by separate teams
- Each component requires different level of scaling
- Each component solve a different business problem
- independently developed and tested
- independently deployed
- independently scaled
- has the most information it needs within itself
16. What is the difference between SOA and Microservices?Service Oriented Achitecture (SOA) is different services developed for different business purpose are made to work together for reusability.
Microservices are services developed to solve an overall business problem.
17. What is Spring cloud?Spring cloud is a collection of tools that help to build cloud applications as a set of microservices. Spring cloud provides the features that the microservices architecture needs.
18. What are the major features provided by Spring cloud for microservices?
- Fault tolerance
- Service Registration and Discovery
- API Gateway
- Load Balancing
- Centralized configuration
19. What are Netflix Open Source Software OSS?Netflix OSS are set of solutions provided by Netflix as Open Source to enable to solve common problems faced in developing microservices or cloud based software.
Popular APIs provided by Netflix are:
- Hystrix for Fault Tolerance
- Eureka for Service Registration and Discovery
- Zuul for API Gateway
- Ribbon for Load Balancing
20. How does spring boot help in microservices development?spring boot provides starters for every spring module and hence spring cloud as well. Thus, spring cloud starters enable faster development of web services
21. What is API gateway?API gateway is the front gate for all requests that hit cloud native or microservice applications. API Gateway are used for:
- Authentication and Authorization
- Load Balancing
- Retrying Failed Requests
- Managing Concurrent Requests
- Request Tracing and Debugging
- Dynamic Routing
- Connection pooling for outgoing connections
- GZip of Outgoing Responses
- Proxy Protocol