DEV Community

Shanaya Hassen
Shanaya Hassen

Posted on

Key Concepts in Spring Boot

While learning Spring Boot, I came across several concepts that are important when developing Java-based backend applications and REST APIs. This article briefly explains some of the key concepts I learned.

1. What is Spring Boot?

Spring Boot is a framework built on top of the Spring Framework that simplifies the development of Java applications. It provides features such as auto-configuration, starter dependencies, and embedded servers, allowing developers to create and run applications with less manual configuration.

For example, a REST API endpoint can be created using annotations such as @RestController and @GetMapping without requiring extensive configuration.

2. Advantages of Spring Boot over Spring

Spring Boot simplifies the development process compared to configuring a Spring application manually. Some key advantages are:

  • Auto-configuration - automatically configures many components based on the project's dependencies.
  • Starter dependencies - provide commonly required dependencies together.
  • Embedded servers - allows applications to run without separately configuring a web server.
  • Less configuration - reduces boilerplate configuration and allows developers to focus on application logic.

3. What is the Purpose of Optional?

Optional is a Java container that can either contain a value or be empty. It is useful when a value may not exist.

For example, when searching for a student by ID, the result can be returned as:

Optional<Student>
Enter fullscreen mode Exit fullscreen mode

This allows the application to explicitly handle both cases instead of directly returning null. For example, an existing student can result in 200 OK, while a missing student can result in 404 Not Found.

4. What are the Main HTTP Status Codes?

HTTP status codes indicate the result of a client's request.

200 OK - Request was successful
201 Created - A new resource was successfully created
204 No Content - Request was successful with no response body
400 Bad Request - Request contains invalid data
401 Unauthorized - Authentication is required or failed
403 Forbidden - Access to the resource is not allowed
404 Not Found - equested resource was not found
500 Internal Server Error - Unexpected error occurred on the server
503 Service Unavailable - Server/service is temporarily unavailable

Using appropriate status codes helps an API clearly communicate the result of each request.

5. What is the Use of Logging?

Logging is the process of recording information about what happens inside an application while it is running.

Logs are useful for:

  • Debugging problems
  • Monitoring application behavior
  • Tracking important events
  • Investigating errors and failures

6. What are the Different Log Levels?

Log levels indicate the importance or severity of a log message.

  • TRACE - very detailed information, mainly useful for deep troubleshooting.
  • DEBUG - information useful for debugging during development.
  • INFO - general information about normal application operations.
  • WARN - indicates a potential problem that does not necessarily stop the application.
  • ERROR - indicates a serious problem or failure.

Using different log levels makes it easier to filter and understand application logs.

7. What are the Advantages of Spring Security?

Spring Security is a framework used to add authentication and authorization to Spring applications.

Some of its advantages include:

  • Authentication – verifies who a user is.
  • Authorization – controls what an authenticated user is allowed to access.
  • Password security – supports secure password encoding and storage.
  • Protection against common attacks – provides security features for applications and web requests.
  • Flexible configuration – allows security rules to be customized according to application requirements.

For example, Spring Security can be used to restrict certain API endpoints so that only authenticated users can access them.

Top comments (0)