Spring Modules
Spring Modules Interview with follow-up questions
1. Can you explain the different modules in the Spring Framework?
The Spring Framework is organized into modules you adopt selectively:
- Core Container (
core,beans,context, SpEL) — IoC/DI, theApplicationContext, and bean lifecycle. The foundation everything else builds on. - AOP — modularizes cross-cutting concerns (logging, security, transactions) via proxies.
- Data Access / Integration — JDBC (
JdbcTemplate/JdbcClient), ORM (JPA/Hibernate), declarative transactions (@Transactional), JMS, and reactive R2DBC. - Web — servlet MVC (
spring-webmvc) and reactive WebFlux (spring-webflux). - Test — context management, slices,
MockMvc/WebTestClientfor integration testing.
Core Container → AOP → Data/Tx → Web (MVC | WebFlux) → Test
The clarification interviewers reward: Security, Spring Boot, Spring Data, Spring Cloud, and Spring Batch are separate projects, not modules of the core framework — a common point of confusion. "Spring" in practice means the framework core plus those projects (especially Spring Boot, which auto-configures the lot). Worth noting the 2026 baseline too: Spring 6/7 on Java 17+ with the jakarta.* namespace.
Follow-up 1
What is the role of the AOP module in Spring?
The AOP (Aspect-Oriented Programming) module in Spring provides support for aspect-oriented programming. AOP allows you to modularize cross-cutting concerns in your application, such as logging, transaction management, and security. With the AOP module, you can define aspects that encapsulate these cross-cutting concerns and apply them to specific join points in your application's code. The AOP module uses proxies or bytecode manipulation to intercept method invocations and apply the defined aspects. This helps in achieving separation of concerns and improves the modularity and maintainability of your application.
Follow-up 2
How does the Web module differ from the Web-MVC module?
The Web module and the Web-MVC module in the Spring Framework both provide support for building web applications, but they have different focuses and functionalities.
The Web module provides general web-related functionality, such as handling HTTP requests, managing sessions, and handling web-related concerns like multipart file uploading, static resource handling, and internationalization. It is a lower-level module that can be used independently of the Web-MVC module.
On the other hand, the Web-MVC module provides support for building web applications using the Model-View-Controller (MVC) architectural pattern. It includes features like request mapping, view resolution, form handling, and data binding. The Web-MVC module builds on top of the Web module and provides higher-level abstractions for building MVC-based web applications.
In summary, the Web module provides general web-related functionality, while the Web-MVC module provides additional features specifically for building MVC-based web applications.
Follow-up 3
What is the purpose of the Test module in Spring?
The Test module in Spring provides support for testing Spring applications. It includes various utilities and annotations that make it easier to write tests for Spring components and applications.
Some of the key features of the Test module include:
Integration Testing: The Test module provides support for integration testing of Spring applications. It allows you to load and configure the Spring application context for testing, and provides utilities for interacting with the application context and its components.
Unit Testing: The Test module provides utilities for unit testing Spring components, such as dependency injection and mocking.
Test Annotations: The Test module includes annotations like
@RunWith,@ContextConfiguration, and@Autowiredthat can be used to configure and customize the testing environment.
Overall, the Test module helps in writing comprehensive and effective tests for Spring applications, ensuring the reliability and correctness of the application's behavior.
Follow-up 4
Can you explain the functionality of the Data Access/Integration module?
The Data Access/Integration module in the Spring Framework provides support for working with databases and other data sources. It includes features for data access, object-relational mapping (ORM), and transaction management.
Some of the key functionalities of the Data Access/Integration module include:
JDBC Support: The module provides a JDBC abstraction layer that simplifies working with relational databases using JDBC. It provides utilities for executing SQL queries, handling transactions, and managing database connections.
ORM Support: The module includes integration with popular ORM frameworks like Hibernate, JPA, and MyBatis. It provides support for object-relational mapping, allowing you to map Java objects to database tables and perform CRUD operations.
Transaction Management: The module provides support for declarative transaction management using annotations or XML configuration. It allows you to define transaction boundaries and manage transactions across multiple data sources.
Data Access Templates: The module includes data access templates that provide higher-level abstractions for common data access operations, reducing boilerplate code and improving productivity.
Overall, the Data Access/Integration module simplifies working with databases and other data sources in Spring applications, making it easier to implement data access and integration logic.
2. What is the role of the Core Container in the Spring Framework?
The Core Container is the IoC container — the foundation of the whole framework. Its role is to create, configure, assemble, and manage the lifecycle of beans, wiring their dependencies through Dependency Injection so your components stay loosely coupled, testable, and configuration-driven.
It's made of:
spring-core/spring-beans— the base IoC machinery andBeanFactory.spring-context— the production container,ApplicationContext(adds events, i18n, resource loading, AOP hooks).spring-expression— SpEL for dynamic configuration values.
@Configuration
class AppConfig { @Bean OrderService orderService(PaymentClient p) { return new OrderService(p); } }
Key points: the container reads configuration metadata (annotations/@Configuration, component scanning, or legacy XML), resolves dependencies by type, manages scopes (singleton by default) and lifecycle callbacks (@PostConstruct/@PreDestroy), and underpins AOP and transactions. In a Spring Boot app, SpringApplication.run() bootstraps this same container for you — you just declare beans with @Component/@Bean and inject them.
Follow-up 1
What are the main components of the Core Container?
The main components of the Core Container are the BeanFactory and the ApplicationContext. The BeanFactory is the central interface for managing and accessing Spring beans. It provides methods for retrieving beans, configuring bean properties, and handling bean lifecycle events. The ApplicationContext is a higher-level interface that extends the functionality of the BeanFactory. It adds support for internationalization, event handling, and resource loading, among other features.
Follow-up 2
Can you explain the concept of a BeanFactory in the Core Container?
In the Core Container, a BeanFactory is responsible for managing and configuring Spring beans. It is the central interface for retrieving beans, configuring bean properties, and handling bean lifecycle events. The BeanFactory uses a configuration metadata, such as XML or Java annotations, to create and configure beans. It also supports various dependency injection techniques, such as constructor injection and setter injection, to wire beans together. The BeanFactory provides a flexible and extensible way to manage beans in a Spring application.
Follow-up 3
How does the Core Container interact with other modules?
The Core Container interacts with other modules in the Spring Framework through well-defined interfaces and APIs. It provides the foundation for other modules to build upon and extends their functionality. For example, the Core Container works closely with the AOP (Aspect-Oriented Programming) module to enable aspect-oriented programming in Spring applications. It also integrates with the Data Access/Integration module to provide seamless database access and integration capabilities.
3. How does the Spring Framework ensure loose coupling between its modules?
Spring achieves loose coupling primarily through Inversion of Control / Dependency Injection combined with programming to interfaces. Components don't construct their collaborators; the container injects them — so a class depends on an abstraction (interface), not a concrete implementation, and you can swap implementations without changing the consumer.
@Service
class CheckoutService {
private final PaymentGateway gateway; // interface, not a concrete type
CheckoutService(PaymentGateway gateway) { this.gateway = gateway; }
}
// Inject StripeGateway, MockGateway, etc. — CheckoutService never changes.
The mechanisms that reinforce this:
- DI by type with
@Qualifier/@Primaryto choose among implementations. - AOP proxies that add behavior (transactions, security) without the business code knowing.
- Bean configuration (Java config / component scanning) kept separate from business logic.
- Abstractions like
DataAccessException,JdbcTemplate, and repository interfaces that hide vendor specifics.
The payoff interviewers want named: testability (inject mocks), flexibility (swap implementations or profiles), and maintainability. The same principle applies whether you're decoupling your own components or the framework's modules from each other.
Follow-up 1
Can you provide an example of loose coupling in Spring?
Sure! In Spring, loose coupling can be achieved by using interfaces and dependency injection. For example, let's say we have a UserService interface and a UserServiceImpl class that implements this interface. Instead of directly creating an instance of UserServiceImpl in our code, we can use dependency injection to inject an instance of UserService into the classes that depend on it. This allows us to easily switch the implementation of UserService without affecting the classes that depend on it, promoting loose coupling.
Follow-up 2
Why is loose coupling important in software development?
Loose coupling is important in software development because it promotes modularity, flexibility, and maintainability. When modules are loosely coupled, they can be developed, tested, and maintained independently, which makes the codebase more modular and easier to understand. Loose coupling also allows for easier integration of new features or changes, as the impact on other modules is minimized. Additionally, loose coupling reduces the risk of cascading failures, as changes in one module are less likely to have unintended consequences on other modules.
Follow-up 3
How does loose coupling contribute to the modularity of the Spring Framework?
Loose coupling is a fundamental principle of the Spring Framework and is one of the key factors that contribute to its modularity. By ensuring that modules are loosely coupled, the Spring Framework allows for easy integration and swapping of components. For example, different implementations of a service interface can be easily plugged into the framework without affecting other parts of the application. This modularity makes the Spring Framework highly flexible and adaptable to changing requirements, as well as promoting code reuse and maintainability.
4. Can you explain how the Web-MVC module in Spring works?
Spring Web MVC is the servlet-based request-processing framework, centered on a front controller, the DispatcherServlet. The request flow:
- The request hits the
DispatcherServlet(the single entry point). - It consults
HandlerMappingto find the controller method that matches the URL/HTTP method. - A
HandlerAdapterinvokes your@Controller/@RestControllermethod, binding path variables, params, and the request body (validation runs here). - For a REST endpoint, the return value is serialized to JSON via an
HttpMessageConverter(Jackson); for a traditional app, the controller returns a logical view name. - In the view case, a
ViewResolverresolves the actual view and renders the response. - The
DispatcherServletwrites the response back.
@RestController
class ProductController {
@GetMapping("/products/{id}")
Product get(@PathVariable Long id) { ... } // returned object → JSON
}
The framing that signals current knowledge: most modern apps build REST APIs (@RestController + JSON), so the ViewResolver/ModelAndView flow is mainly for server-rendered views (Thymeleaf). The whole pipeline runs on the servlet stack — now cheaper to scale with virtual threads — while WebFlux is the reactive alternative when you need non-blocking concurrency. @ControllerAdvice/@ExceptionHandler centralize exception handling across controllers.
Follow-up 1
What is the DispatcherServlet and what role does it play in the Web-MVC module?
The DispatcherServlet is a central component in the Web-MVC module of Spring. It acts as a front controller, intercepting all incoming requests and dispatching them to the appropriate controller for processing. The DispatcherServlet is responsible for managing the entire request-response lifecycle, including request parsing, handler mapping, view resolution, and response rendering.
The DispatcherServlet is configured in the web.xml file of a Spring web application and is typically mapped to a specific URL pattern. When a request is received that matches the URL pattern, the DispatcherServlet is invoked and takes over the processing of the request.
Follow-up 2
How does the Web-MVC module handle request mapping?
The Web-MVC module in Spring provides several ways to handle request mapping:
Annotation-based: Controllers can use annotations such as @RequestMapping, @GetMapping, @PostMapping, etc., to map specific URLs or URL patterns to methods. For example, @RequestMapping(value = "/users", method = RequestMethod.GET) maps the /users URL to a method that handles GET requests.
XML-based: Request mappings can also be defined in XML configuration files using the element. This allows for more fine-grained control over the mappings.
Default mappings: The Web-MVC module provides default mappings for common scenarios, such as serving static resources (e.g., CSS, JavaScript files) or handling error pages.
The chosen approach depends on the specific requirements of the application and the preferences of the development team.
Follow-up 3
Can you explain the role of the ViewResolver in the Web-MVC module?
The ViewResolver is responsible for resolving the logical view name returned by the controller into an actual view implementation that will render the response. It plays a crucial role in the Web-MVC module of Spring.
The ViewResolver interface defines a single method, resolveViewName(), which takes the logical view name as input and returns a View object. The View object is responsible for rendering the response, typically by generating HTML or other markup.
Spring provides several implementations of the ViewResolver interface, such as InternalResourceViewResolver (for JSP views), FreeMarkerViewResolver (for FreeMarker templates), and ThymeleafViewResolver (for Thymeleaf templates). The chosen ViewResolver depends on the view technology being used in the application.
By separating the logical view name from the actual view implementation, the ViewResolver allows for flexibility and easy switching between different view technologies without changing the controller code.
5. What is the purpose of the Spring Boot module?
Spring Boot exists to make Spring fast to start and production-ready by default, removing the heavy manual configuration that plain Spring used to require. It's not a replacement for the Spring Framework — it's a layer on top that wires sensible defaults.
What it provides:
- Auto-configuration — inspects the classpath and beans and configures things automatically (a
DataSourceif a JDBC driver is present, an MVC stack ifspring-webis there, etc.). - Starters — curated, version-aligned dependency bundles (
spring-boot-starter-web,-data-jpa,-security) that end "dependency hell." - Embedded server — Tomcat/Jetty/Netty built in, so the app runs as a self-contained
java -jar(a "fat jar"), ideal for containers and microservices. - Externalized configuration —
application.properties/.yml, profiles, environment variables. - Production features — Actuator (health, metrics, info) and Micrometer observability.
@SpringBootApplication
public class App { public static void main(String[] a){ SpringApplication.run(App.class, a); } }
The 2026 framing: Spring Boot is the standard way to build Spring apps, and current versions (Boot 3.x/4.x) require Java 17+, use the jakarta.* namespace, and support GraalVM native images (AOT) and virtual threads for faster startup and cheaper concurrency.
Follow-up 1
How does Spring Boot simplify the development of Spring applications?
Spring Boot simplifies the development of Spring applications in several ways:
- Opinionated Defaults: Spring Boot provides sensible defaults for configuration, reducing the need for manual configuration.
- Auto-configuration: Spring Boot automatically configures the application based on the dependencies and classpath, reducing the need for explicit configuration.
- Embedded Servers: Spring Boot includes embedded servers like Tomcat or Jetty, allowing developers to run applications without the need for external server setup.
- Dependency Management: Spring Boot manages the dependencies and their versions, ensuring compatibility and simplifying dependency management.
- Production-Ready Features: Spring Boot includes features like health checks, metrics, and externalized configuration, making it easier to build production-ready applications.
Follow-up 2
What is the role of the Spring Boot Starter modules?
The Spring Boot Starter modules provide a convenient way to include commonly used dependencies in a Spring Boot application. They are designed to simplify the dependency management and configuration of the application. Each Starter module includes a set of dependencies related to a specific functionality, such as web development, data access, or security. By including a Starter module, developers can easily add the required dependencies to their project without manually specifying each dependency.
Follow-up 3
Can you explain the concept of auto-configuration in Spring Boot?
Auto-configuration is a key feature of Spring Boot that automatically configures the Spring application based on the dependencies and classpath. It eliminates the need for explicit configuration by analyzing the environment and applying sensible defaults. Spring Boot achieves auto-configuration through the use of @EnableAutoConfiguration annotation, which triggers the automatic configuration process. The auto-configuration classes are typically included in the Spring Boot Starter modules and are activated when the required dependencies are present. If needed, developers can also customize the auto-configuration by excluding specific classes or providing their own configuration.
Live mock interview
Mock interview: Spring Modules
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.