Spring boot Interview Questions and answer. Spring Boot is a project that is built on the top of the Spring Framework. It provides an easier and faster way to set up, configure, and run both simple and web-based applications. Also it is a Spring module that provides the RAD (Rapid Application Development) feature to the Spring Framework. It is used to create a stand-alone Spring-based application that you can just run because it needs minimal Spring configuration. Moreover in Spring Boot, there is no requirement for XML configuration (deployment descriptor). In addition it uses convention over configuration software design paradigm that means it decreases the effort of the developer.
Now that we have a brief introduction of Spring boot. Let us now take a look at some of the frequently asked Spring boot Interview Questions and answer
1. What is Spring Boot and mention the need for it?
Spring Boot is a Spring module that aims to simplify the use of the Spring framework for Java development. It is used to create stand-alone Spring-based applications that you can just run. So, it basically removes a lot of configurations and dependencies. Moreover aiming at the Rapid Application Development, Spring Boot framework comes with the auto-dependency resolution, embedded HTTP servers, auto-configuration, management endpoints, and Spring Boot CLI.
2. List some of the major advantages of using Spring boot.
Some of the important advantages of using Spring boot are:
- Create stand-alone Spring applications that can be started using java -jar.
- Embed Tomcat, Jetty or Undertow directly. You don’t need to deploy WAR files.
- It provides opinionated ‘starter’ POMs to simplify your Maven configuration.
- It automatically configure Spring whenever possible.
3. Mention some of the eminent features provided by Spring boot.
Few important features of Spring Boot are as follows:
- Spring CLI – Spring Boot CLI allows you to Groovy for writing Spring boot application and avoids boilerplate code.
- Starter Dependency – With the help of this feature, Spring Boot aggregates common dependencies together and eventually improves productivity
- Auto-Configuration – The auto-configuration feature of Spring Boot helps in loading the default configurations according to the project you are working on. In this way, you can avoid any unnecessary WAR files.
- Spring Initializer – This is basically a web application, which can create an internal project structure for you. So, you do not have to manually set up the structure of the project, instead, you can use this feature.
- Spring Actuator – This feature provides help while running Spring Boot applications.
4. What happens in the background when Spring Boot Application is run as Java Application?
When a Spring Boot application is executed as “Run as Java application”, then it automatically launches up the tomcat server as soon as it sees, that you are developing a web application.
5. How to create Spring Boot application using Maven?
- Spring Boot CLI
- Also Spring Starter Project Wizard
- Spring Initializr
- Spring Maven Project
6. Can we change the port of the embedded Tomcat server in Spring boot?
Yes, we can change the port of the embedded tomcat server by using the application properties file. In this file, you have to add a property of “server.port” and assign it to any port you wish to. For example, if you want to assign it to 8081, then you have to mention server.port=8081. Once you mention the port number, the application properties file will be automatically loaded by Spring Boot and the required configurations will be applied on to the application.
7. What are the @RequestMapping and @RestController annotation in Spring Boot used for?
|This annotation is used to provide the routing information and tells to Spring that any HTTP request must be mapped to the respective method.||This annotation is used to add the @ResponseBody and @Controller annotation to the class|
|To use this annotation, you have to import org.springframework.web. bind.annotation.RequestMapping;||To use this annotation, you have to import org.springframework.web. bind.annotation.RestController;|
8. Explain Spring Data.
Spring Data aims to make it easy for the developers to use relational and non-relational databases, cloud-based data services, and other data access technologies. So, basically, it makes it easy for data access and still retains the underlying data.
9. Give an example for ReadOnly as true in Transaction management?
Example for ReadOnly as TRUE in transaction management could be as follows:
So, consider a scenario, where you have to read data from the database. For example, let us say you have a customer database, and you want to read the customer details such as customerID, and customername. So, to do that, you will set read-only on the transaction as we do not want to check for the changes in the entities.
10. Mention the steps to create a Spring Boot project using Spring Initializer.
Spring Initializr is a web tool provided by Spring. With the help of this tool, you can create Spring Boot projects by just providing project details. The following steps need to be followed to create a Spring Boot project using Spring Initializer:
- Choose the maven project and the required dependencies. Then, fill in the other required details like Group, Artifact, and then click on Generate Project.
- Once the project is downloaded, extract the project onto your system
- Next, you have to import this project using the import option on the Spring Tool Suite IDE
- While importing the project, remember that you have to choose the project type to be Maven and the source project should contain the pom.xml file.
Once, all the above steps are followed you will see that the Spring Boot project is created with all the required dependencies.
11. Can we create a non-web application in Spring Boot?
Yes, we can create a non-web application by removing the web dependencies from the classpath along with changing the way Spring Boot creates the application context.
12. In which layer, should the boundary of a transaction start?
The boundary of the transaction should start from the Service Layer since the logic for the business transaction is present in this layer itself.
13. What do you think is the need for Profiles?
Profiles are used to provide a way to segregate the different parts of the application configuration and make it available for various environments. So, basically, any @Component or a @Configuration can be marked with a @Profile to limit as it is loaded. Consider you have multiple environments,
So, let’s say, you want to have different application configuration in each of the environments, you can use profiles to have different application configurations for different environments. So, basically, Spring and Spring Boot provide features through which you can specify:
- The active profile for a specific environment
- The configuration of various environments for various profiles.
14. Why is Spring Data REST not recommended in real-world applications?
So Spring Data REST is not recommended in real-world applications as you are exposing your database entities directly as REST Services. While designing RESTful services, the two most important things that we consider is the domain model and the consumers. But, while using Spring Data REST, none of these parameters are considered. Moreover, the entities are directly exposed. So, I would just say, you can use Spring Data REST, for the initial evolution of the project.
15. What is the name of the default H2 database configured by Spring Boot?
The name of the default H2 database is testdb. Refer below:
spring.datasource.name=testdb # Name of the datasource.
So these were some of the major Spring boot Interview Questions and answer. But do not stop here, keep learning and exploring on the technology to have a better grasp over the concepts.
Similar articles – Spring boot Interview Questions and answer
- Benefits of Using Angular for Web Development 2021
- Difference Between C vs C++ vs Python vs Java
- KALI Linux Not Prefer Software Development Ubuntu
- Angular 12 Performance Benchmark Install Features
- Setup Angular 12 vs 11 vs 10 features benchmark