springboot_interview_questions
springboot_interview_questions
Spring Boot is an open-source Java-based framework used to create stand-alone, production-ready Spring applications
with minimal configuration. It simplifies the development process by providing default configurations, embedded servers,
and various dependencies.
• Embedded Server: Includes Tomcat, Jetty, or Undertow without needing external setup.
• Spring Boot CLI: Allows running Spring Boot applications from the command line.
Spring Boot Starters are dependency descriptors that simplify the inclusion of related libraries in a project. Examples
include:
Spring Boot Auto-Configuration automatically configures components based on classpath dependencies. It reduces
manual configuration and provides ready-to-use beans.
6. What is the purpose of the application.properties or application.yml file?
These files are used to configure various aspects of a Spring Boot application, such as:
logging.level.org.springframework=DEBUG
Spring Boot Actuators provide production-ready features for monitoring and managing applications. Common actuator
endpoints include:
Spring Boot DevTools is a module that enhances the development experience by enabling:
Annotation Purpose
• Using @ExceptionHandler:
• Using @ResponseStatus:
Annotation Description
• JDBC (spring-boot-starter-jdbc)
13. What is Spring Boot’s default embedded server? How can we change it?
Spring Boot uses Tomcat as the default embedded server. It can be changed to Jetty or Undertow by excluding springboot-
starter-tomcat and adding dependencies like:
14. How do you create a Spring Boot application?
spring.profiles.active=dev
Spring Boot Security provides authentication and authorization. By default, it secures all endpoints with a generated
password. To configure a custom username and password:
• Microservices architecture
• Exception handling
Spring Boot Actuator is a sub-project of Spring Boot that provides production-ready features
• Health checks.
• Metrics.
• Application info.
• Environment details.
It helps monitor and manage the application in production.
22. Explain the internal working of Spring Boot.
Spring Boot works by automatically setting up default configurations based on the tools our project uses. It includes
builtin servers like Tomcat to run our applications. Special starter packages make it easy to connect with other
technologies. We can customize settings with simple annotations and properties files. The Spring Application class starts
the app, and Spring Boot Actuator offers tools for monitoring and managing it.
24) Is it possible to change the port of the embedded Tomcat server in Spring Boot?
Yes, we can change the default port of the embedded Tomcat server in Spring Boot. This can be done by setting the
server.port property in the application.properties or application.yml file to the desired port number.
The default port for Tomcat in Spring Boot is 8080. This means when a Spring Boot application with an embedded Tomcat
server is run, it will, by default, listen for HTTP requests on port 8080 unless configured otherwise
Spring Boot Actuator is like a toolbox for monitoring and managing our Spring Boot application. It gives us endpoints
(think of them as special URLs) where we can check health, view configurations, gather metrics, and
more. It's super useful for keeping an eye on how your app is doing.
In a production environment (which is like the real world where your app is being used by people), these endpoints can
reveal sensitive information about your application. Imagine leaving our diary open in a public place – we wouldn't want
that, right? Similarly, we don't want just anyone peeking into the internals of your application.
Limit Exposure: By default, not all actuator endpoints are exposed. We can control which ones are available over the web.
It's like choosing what parts of your diary are okay to share.
Use Spring Security: We can configure Spring Security to require authentication for accessing actuator endpoints.
Actuator Role: Create a specific role, like ACTUATOR_ADMIN, and assign it to users who should have access. This is like
giving a key to only trusted people.
28) What is Spring Profiles? How do you start an application with a certain profile?
Spring Profiles provide a way to segregate parts of our application configuration and make it only available in certain
environments. For example, we can define database configurations for development, testing, and production
environments without them interfering with each other. To start an application with a specific profile, we can use the
Dspring.profiles.active=profile_name parameter in our command line when launching the application, or set the
spring.profiles.active property in our application's configuration files.