0% found this document useful (0 votes)
9 views2 pages

Spring Framework Essentials: IoC, AOP, MVC

Uploaded by

pibexik122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Spring Framework Essentials: IoC, AOP, MVC

Uploaded by

pibexik122
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ Spring Core (IoC + DI)

■ What is Inversion of Control (IoC)?


■ IoC is a design principle where the control of creating objects and managing dependencies is
shifted from the object itself to a container (in Spring, the IoC container).

■ What is Dependency Injection (DI)?


■ DI is a form of IoC where the container injects required objects into a class at runtime, promoting
loose coupling and testability. Constructor, setter, and field injection are supported.

■ Spring AOP

■ What is an Aspect?
■ An Aspect is a module in AOP that encapsulates a cross-cutting concern like logging, security, or
transaction management.

■ Types of advice in Spring AOP?


■ Advice is code that runs at a Join Point: @Before, @After, @AfterReturning, @AfterThrowing,
@Around.

■ Spring Data Access

■ What is JdbcTemplate?
■ JdbcTemplate is a helper class that reduces boilerplate in JDBC by handling connection
management and exceptions, letting developers focus on SQL and mapping logic.

■ What is @Transactional?
■ It marks methods or classes to run within a transaction boundary. Spring manages commit or
rollback automatically.

■ Spring MVC

■ What is DispatcherServlet?
■ It is the front controller of Spring MVC that routes requests to appropriate controllers and resolves
views.

■ Difference between @Controller and @RestController?


■ @RestController = @Controller + @ResponseBody, returning data directly instead of rendering
views.

■ Spring Security
■ What is SecurityContext?
■ It holds authentication and security information for the current thread of execution.

■ Why use BCryptPasswordEncoder?


■ It securely hashes passwords with salts and is resistant to brute-force attacks.

■ Spring Boot

■ What problem does Spring Boot solve?


■ It reduces configuration boilerplate by providing auto-configuration, opinionated defaults, and
embedded servers.

■ What is auto-configuration?
■ Spring Boot auto-configures beans based on the classpath, existing beans, and property files.

■ Spring Boot Actuator

■ What is Spring Boot Actuator?


■ It provides production-ready endpoints for monitoring, metrics, and health checks.

■ Spring Boot Testing

■ What does @SpringBootTest do?


■ It loads the full Spring context for integration testing.

■ What is MockMvc?
■ It simulates HTTP requests to test controllers without starting a server.

■ Other Features

■ How does Spring caching work?


■ By using @EnableCaching and annotations like @Cacheable, method results can be cached for
performance.

■ What is @Async?
■ It allows methods to run asynchronously in separate threads, enabling non-blocking execution.

Common questions

Powered by AI

JdbcTemplate offers several advantages for data access in Spring applications by abstracting repetitive JDBC operations. It handles connection management, facilitates exception translation, and reduces boilerplate code, allowing developers to focus more on SQL implementation and data mapping within applications rather than on setting up connections or managing resource cleanup. This leads to cleaner and more maintainable code and reduces the potential for resource leaks .

SecurityContext in Spring Security is pivotal in managing authentication and security context for the current thread of execution. It stores important security-related information, such as the authenticated User object, credentials, and the authorities granted to a user. This allows Spring Security to make authorization decisions consistently throughout the request scope. SecurityContext ensures that security is seamlessly integrated into the application flow, maintaining security data that can be leveraged when assessing permissions and accessing sensitive resources .

In Spring MVC, the DispatcherServlet acts as a front controller by centralizing the handling of all incoming HTTP requests. It routes requests to the appropriate Controller classes, which then process the requests and return models and views. This design enables separation of concerns, as the DispatcherServlet handles routing, view resolution, and acts as an intermediary that delegates tasks to specific components, thus streamlining the application architecture and improving maintainability .

Inversion of Control (IoC) contributes to loose coupling by shifting the responsibility of managing object creation and dependencies from the object itself to an IoC container. This means that instead of a class handling its own dependencies, the container manages them and injects they are needed. This allows developers to change implementations or dependencies with minimal impact on the consuming classes, as they no longer need direct knowledge of class constructors or other dependencies, thereby promoting a more modular and testable codebase .

BCryptPasswordEncoder is essential for password security in applications because it provides robust hashing of passwords with salting, which is crucial for protecting against brute-force attacks. BCrypt uses an adaptive hashing algorithm that can be calibrated to become slower as hardware improves, thereby defending against future attacks. This Encoder generates a unique salt for each password and applies a hashing function that transforms the password into a series of random characters, making it computationally infeasible to decrypt or crack the original password. Its use significantly enhances security by ensuring that even if password hashes are exposed, attackers cannot easily reverse-engineer the original passwords .

@Async in Spring allows methods to run asynchronously, improving application performance and responsiveness by delegating longer-running, blocking operations to separate threads. This means that when an @Async method is called, the caller does not need to wait for the method completion and can continue executing other tasks, thus improving throughput and reducing perceived wait time for end-users. This is particularly beneficial for applications that handle a significant amount of processing logic or require I/O operations, as it can significantly reduce bottlenecks and enhance user experience by responding faster .

@Controller and @RestController have overlapping responsibilities in Spring MVC but differ fundamentally in their responses. @Controller is a stereotype annotation for classes that hold business logic and return views, meaning it typically works with templates to render HTML view responses. In contrast, @RestController is an extension of @Controller combined with @ResponseBody. This combination allows @RestController to handle HTTP requests by returning JSON or XML data directly rather than rendering views. This makes @RestController particularly suitable for API development, where returning structured data, not HTML, is often desired .

The @Transactional annotation in Spring is utilized to demarcate the transaction boundaries declaratively. When a method or a class is annotated with @Transactional, Spring ensures that code within the transactional boundary is executed in a transactional context. This includes automatic management of commit and rollback operations depending on whether runtime exceptions occur. The benefits of using @Transactional include simplified transaction management, as developers do not need to manage transaction boundaries programmatically, as well as consistent data integrity during complex operations that include multiple data modifications .

Spring Boot addresses the challenge of complex configuration and setup in traditional Spring applications by providing a simpler and quicker way to get an application running. It introduces opinionated defaults and embedded servers, minimizing the need for extensive setup. The auto-configuration feature plays a crucial role in this by automatically configuring Spring beans based on the classpath settings, existing beans, and various property files. Auto-configuration reduces developer burden by eliminating the need for detailed configuration files, speeding up application development and deployment .

In Spring AOP, an Aspect is a module that encapsulates cross-cutting concerns, such as logging or security, that affect multiple points of an application. Advice refers to the action taken by an aspect at a particular Join Point, or specific points during execution. There are different types of advice, including @Before, @After, @AfterReturning, @AfterThrowing, and @Around, which determine when the cross-cutting logic should be executed in relation to the method execution .

You might also like