10 Spring Boot interview questions you must prepare 2023
If you are preparing for the spring boot Interview here are the 10 important basic questions you must prepare before you attend the interview.
1. How to create a Spring Boot application?
There are multiple ways to create a Spring Boot application.
- Creating spring boot application with spring initializer.
- Manually creating maven projects and adding Spring Boot dependencies.
- Using Spring Boot CLI
2. How does the Spring Boot application get started?
SpringApplication.run() method is the starting point of the Spring Boot application, all the necessary configurations get kicked off from this method, and this run method is called from the main method of the application.
Spring uses annotations like :
@Configuration — This marks the class as the source of beans.
@EnableAutoconfiguration — Based on the classpath it adds the dependencies, for example, if spring-web is added to the classpath it will set up the dispatcher-servlet for the application.
3. What are the features/Advantages of Spring Boot?
Below are a few features of Spring Boot which make it easier to develop the production-grade application, these features of Spring Boot are the reason it is one of the most powerful tools for building Microservices and RESTFUL web services.
- AutoConfiguration — Spring boot configures the application automatically based on dependencies included in the classpath.
- Embedded Web Server- Spring boot supports embedded web servers like, TomCat, and Jetty.
- Spring Boot Actuator — Actuator provides endpoints for application health, metrics and more, which makes it easy to monitor the application.
- Stand Alone — Spring boot applications are standalone and come with embedded servers like Tomcat
- Spring Security — Spring Boot provides authentication and authorisation features to secure the application.
- Spring initializer — It is a web-based tool that allows you to quickly generate a Spring Boot application, which you can just run.
- Externalised Configuration — Spring Boot allows you to provide necessary configuration using configuration files like Application.json, and application. yaml.
4. What are the key dependencies of Spring Boot?
Some key starters and its dependencies are :
Spring Boot Starter Web: Used for building web applications
- Spring Boot Starter Data JPA — This includes Java Persistence API dependencies for database access.
- Spring Boot Starter Test — Used for writing unit tests and integration tests.
- Spring Boot Starter Actuator- This adds features to manage and monitor the application’s health
- Spring Boot Starter Security — Used for Authentication and Authorisation
5. How do you connect the Spring Boot application to the database?
These are the steps we need to follow to connect our spring boot application to the database.
- Adding Depedencies
- Adding database configuration in application.properties
- Creating Entity class
- Creating and using JPA Repository Interface
6. What are profiles in the Spring Boot, and how to configure them?
Spring boot profile is the feature which allows us to create different sets of configurations for different environments like development, testing, staging and production.
We can activate the specific profile by setting the spring_active_profile property in the configuration file.
7. What is a Spring Boot actuator?
Spring Boot actuator provides production-ready features like endpoints for application health, monitoring and metrics.
8.How to override default configuration of spring boot application ?
We can override the default configuration of the spring boot application using configuration files like application.properties and application. yaml, for example default port configuration for the spring boot application is 8080, if we want to run our application on a different port we would include a server. port: 8080 in our application.properties file.
9. What are key annotations used in Spring Boot?
@SpringBootApplication which includes @EnableAutoConfiguration, @ComponentScan and @Configuration are key components to getting started with Spring Boot Application. Along with these annotations @Controller, @Service, and @Repository are a few important annotations used in Spring Boot.
10. How do you create Restful API using Spring Boot?
We can create Restful API using Spring Boot Controller with the help of annotations like @RequestMapping and @RestController. We can right methods to create API in the controller using HTTP GET, POST, PUT, and DELETE method.
And that’s it, you have taken the first steps towards preparing for your interview. These questions will help you revise the fundamentals of Spring Boot.
If you wish to do hands-on and learn more advanced topics of Spring Boot Consider reading the following articles.
I would love to hear your thoughts on this article and if you have any doubts, questions, or feedback feel free to drop it into the comments section.
If this article helps you Give a Clap, follow and subscribe to my newsletter which will keep you posted the next time I publish the article.
Thank you for reading and keep learning !!!