Spring Architecture


Spring Architecture Interview with follow-up questions

1. Can you explain the architecture of the Spring Framework?

Spring is a lightweight, modular framework built around the IoC container, which creates, configures, and wires your beans via Dependency Injection. Layered around that core are modules you opt into:

  • Core Container (core, beans, context, SpEL) — the IoC container and bean lifecycle; ApplicationContext is the central interface.
  • AOP — cross-cutting concerns via proxies (powers @Transactional, security, caching).
  • Data Access / Integration — JDBC, ORM/JPA, transactions (@Transactional), JMS, R2DBC.
  • Web — servlet MVC (spring-webmvc) and reactive WebFlux (spring-webflux).
  • Test — first-class integration testing support.
                ┌──────────── Web (MVC / WebFlux) ────────────┐
Core Container ─┤  AOP   │  Data Access / Transactions  │ Test │
                └─────────────────────────────────────────────┘

The framing interviewers expect in 2026: this Spring Framework core sits beneath the broader ecosystem — Spring Boot (auto-configuration, embedded server), Spring Data, Security, Cloud, Batch — which is what teams actually build on. Mention the current foundation too: Spring 6/7 on Java 17+, the jakarta.* namespace, and AOT/native + virtual-thread support. The architecture's whole point is modularity + IoC, so you assemble only what you need.

↑ Back to top

Follow-up 1

What are the different modules in Spring Framework?

The Spring Framework is composed of several modules that provide different functionalities. Some of the key modules in the Spring Framework are:

  1. Core Container: This module provides the fundamental functionality of the framework, including DI, AOP, and lifecycle management.

  2. AOP: This module provides support for Aspect-Oriented Programming, allowing developers to modularize cross-cutting concerns in their applications.

  3. Web: This module provides support for web application development, including features such as MVC, RESTful web services, and WebSocket.

  4. Data Access/Integration: This module provides support for data access and integration with databases and other data sources.

  5. Test: This module enhances the testing capabilities of the framework, providing support for unit testing and integration testing.

These modules can be used individually or in combination to build enterprise applications in Java using the Spring Framework.

Follow-up 2

Can you explain the role of the Core Container in Spring?

The Core Container is a key module in the Spring Framework and is responsible for providing the fundamental functionality of the framework. It includes features such as Dependency Injection (DI), Aspect-Oriented Programming (AOP), and lifecycle management.

The Core Container is responsible for managing the beans, which are the objects that form the backbone of the application. It provides a mechanism for creating and configuring beans, as well as managing their lifecycle. The DI feature of the Core Container allows for loose coupling between objects, making the application more modular and easier to maintain.

In addition to DI, the Core Container also provides support for AOP. AOP allows developers to modularize cross-cutting concerns, such as logging, security, and transaction management, and apply them to multiple objects in a declarative manner.

Overall, the Core Container plays a crucial role in providing the foundation for building enterprise applications in Java using the Spring Framework.

Follow-up 3

How does the AOP module work in Spring?

The AOP (Aspect-Oriented Programming) module in the Spring Framework provides support for modularizing cross-cutting concerns in an application. A cross-cutting concern is a functionality that cuts across multiple modules or components of an application, such as logging, security, and transaction management.

In Spring AOP, aspects are used to encapsulate cross-cutting concerns. An aspect is a modular unit of cross-cutting functionality that can be applied to multiple objects in a declarative manner. Aspects are defined using a combination of pointcuts and advice.

A pointcut is a predicate that matches join points in the application. Join points are specific points in the execution of the application, such as method invocations or exception handling. Pointcuts define where the advice should be applied.

Advice is the actual code that is executed when a join point matches a pointcut. There are different types of advice, such as before advice, after advice, and around advice, which allow developers to perform actions before, after, or around the execution of a join point.

The AOP module in Spring uses proxy-based AOP, which means that it creates proxy objects that wrap the target objects and intercept method invocations to apply the advice. This allows for the separation of cross-cutting concerns from the core business logic of the application.

Overall, the AOP module in Spring provides a powerful mechanism for modularizing and managing cross-cutting concerns in an application.

Follow-up 4

What is the purpose of the Web module in Spring?

The Web module in the Spring Framework provides support for web application development. It includes features such as the Model-View-Controller (MVC) pattern, RESTful web services, and WebSocket.

The MVC pattern is a design pattern that separates the application logic into three components: the model, the view, and the controller. The model represents the data and business logic of the application, the view is responsible for rendering the user interface, and the controller handles the user input and coordinates the interaction between the model and the view. The Web module in Spring provides a powerful and flexible MVC framework that simplifies the development of web applications.

In addition to MVC, the Web module also provides support for RESTful web services. REST (Representational State Transfer) is an architectural style for building web services that are scalable, stateless, and can be easily consumed by clients. The Web module in Spring includes features for building and consuming RESTful web services.

Furthermore, the Web module also provides support for WebSocket, which is a communication protocol that allows for real-time, bidirectional communication between a client and a server over a single, long-lived connection. WebSocket is particularly useful for applications that require real-time updates, such as chat applications or stock tickers.

Overall, the Web module in Spring provides a comprehensive set of features for developing web applications in Java.

Follow-up 5

How does the Test module enhance the testing capabilities in Spring?

The Test module in the Spring Framework enhances the testing capabilities of the framework by providing support for unit testing and integration testing.

The Test module includes features such as the Spring TestContext Framework, which provides a powerful and flexible framework for testing Spring applications. The TestContext Framework allows for the creation of test contexts, which are isolated environments for running tests. Test contexts can be configured with specific beans and dependencies, allowing for fine-grained control over the test environment.

In addition to the TestContext Framework, the Test module also provides support for testing Spring MVC applications, RESTful web services, and database interactions. It includes features such as the MockMvc framework, which allows for the simulation of HTTP requests and responses in unit tests, and the TestRestTemplate, which provides a convenient way to test RESTful web services.

Furthermore, the Test module also includes support for transaction management in tests, allowing for the testing of transactional behavior in Spring applications.

Overall, the Test module in Spring enhances the testing capabilities of the framework and provides developers with powerful tools for testing their Spring applications.

2. What is the role of the Spring Core Container?

The Core Container is the heart of Spring: the IoC container that instantiates, configures, assembles, and manages the lifecycle of beans and their dependencies. It reads your configuration (annotations/Java config, or legacy XML), builds the object graph through Dependency Injection, and hands you fully-wired beans.

Its pieces:

  • spring-core / spring-beans — the fundamental IoC and BeanFactory machinery.
  • spring-context — the ApplicationContext, the production container (a BeanFactory superset adding events, i18n, AOP integration, and resource loading).
  • spring-expressionSpEL for dynamic values in configuration.
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
OrderService svc = ctx.getBean(OrderService.class);   // fully wired

Points worth making: the container resolves dependencies by type (with @Qualifier/@Primary to disambiguate), manages scopes (singleton by default) and lifecycle callbacks (@PostConstruct/@PreDestroy), and is what enables loose coupling and testability. In a Spring Boot app you rarely create the context yourself — SpringApplication.run(...) bootstraps it — but it's the same Core Container underneath.

↑ Back to top

Follow-up 1

What is the difference between BeanFactory and ApplicationContext?

BeanFactory is the basic interface for accessing the Spring container and managing beans. It provides the basic functionality for bean instantiation, configuration, and lifecycle management. ApplicationContext is a sub-interface of BeanFactory and provides additional features such as internationalization, event propagation, and application context hierarchy. ApplicationContext is generally preferred over BeanFactory for most applications.

Follow-up 2

How does the Core Container support Dependency Injection?

The Core Container supports Dependency Injection (DI) by allowing objects to be configured and wired together through XML configuration files, Java annotations, or Java code. DI eliminates the need for objects to create their dependencies and instead provides them through constructor injection, setter injection, or method injection. This allows for loose coupling and easier testing and maintenance of the application.

Follow-up 3

Can you explain the lifecycle of a Bean in the Core Container?

The lifecycle of a bean in the Core Container consists of several phases:

  1. Instantiation: The bean is created by calling its constructor or factory method.
  2. Dependency Injection: The bean's dependencies are injected either through constructor injection, setter injection, or method injection.
  3. Initialization: The bean's initialization methods are called, such as @PostConstruct methods or custom init methods.
  4. Usage: The bean is now ready to be used by other components.
  5. Destruction: When the application context is closed, the bean's destruction methods are called, such as @PreDestroy methods or custom destroy methods.

Follow-up 4

What are the different types of IOC containers in Spring?

Spring provides two types of IOC containers:

  1. BeanFactory: This is the basic IOC container that provides the core functionality for managing beans. It lazily initializes beans and provides basic dependency injection.
  2. ApplicationContext: This is a more advanced IOC container that extends BeanFactory. It provides additional features such as internationalization, event propagation, and application context hierarchy. ApplicationContext is generally preferred over BeanFactory for most applications.

3. How does the AOP module in Spring enhance the modularity of a Spring application?

The AOP module improves modularity by letting you pull cross-cutting concerns — logging, security, caching, transaction management, metrics — out of your business classes and into self-contained aspects applied declaratively. Without AOP, that code is duplicated across every service method, tangling infrastructure with domain logic; with it, the concern lives in one place and is woven into the relevant methods by pointcut expressions.

The benefits to state:

  • Single responsibility — business classes focus on business logic; the aspect owns the cross-cutting behavior.
  • DRY / no duplication — define once, apply to many join points.
  • Maintainability — change the concern (e.g. logging format) in one spot.
@Aspect @Component
class AuditAspect {
  @AfterReturning("@annotation(Audited)")
  void audit(JoinPoint jp) { /* record the call */ }
}

The mechanics interviewers expect: Spring AOP is proxy-based and targets Spring-managed beans' method executions, which is exactly how Spring implements @Transactional, @Cacheable, @Async, and method security — so AOP isn't just a feature, it's the foundation those declarative features rely on. (Remember the self-invocation caveat: internal calls bypass the proxy.)

↑ Back to top

Follow-up 1

Can you explain the concept of an Aspect in Spring AOP?

In Spring AOP, an aspect is a modular unit of cross-cutting functionality that can be applied to multiple components in an application. It encapsulates the cross-cutting concerns, such as logging or security, and provides a way to apply them to specific join points in the application. An aspect consists of advice and pointcut expressions. Advice defines the action to be taken at a particular join point, while pointcut expressions specify the join points where the advice should be applied. Aspects can be defined using XML configuration or using annotations in Spring.

Follow-up 2

What is a Pointcut in Spring AOP?

In Spring AOP, a pointcut is a predicate that matches join points in the application. Join points are specific points in the execution of the application, such as method invocations, method executions, or field access. Pointcut expressions are used to define the criteria for matching join points. These expressions can be based on method names, method parameters, class names, annotations, and other factors. Pointcuts are used in conjunction with advice to determine where the advice should be applied in the application.

Follow-up 3

How does Advice work in Spring AOP?

In Spring AOP, advice is the action to be taken at a particular join point in the application. It represents the cross-cutting functionality that needs to be applied. There are different types of advice in Spring AOP, such as before advice, after advice, around advice, etc. Before advice is executed before the join point, after advice is executed after the join point, and around advice wraps around the join point, allowing the advice to control the flow of execution. Advice is associated with pointcuts to determine where it should be applied in the application.

Follow-up 4

Can you give an example of where you would use Spring AOP in an application?

One example of where you would use Spring AOP in an application is for logging. Logging is a cross-cutting concern that needs to be applied to multiple components in an application. Instead of adding logging code to each component, you can define a logging aspect in Spring AOP and apply it to the desired join points, such as method invocations or method executions. This way, the logging functionality is separated from the core business logic, promoting modularity and code reusability.

4. Can you explain the functionality of the Web module in Spring?

The Web module provides Spring's web support, in two distinct stacks you should distinguish:

  • spring-web — shared web infrastructure: the HTTP client/server abstractions, multipart/file uploads, filters, and integration with the servlet API.
  • spring-webmvc — the classic servlet-based, blocking MVC framework: DispatcherServlet, @Controller/@RestController, request mapping, data binding, validation, view resolution, and REST endpoints.
  • spring-webflux — the reactive, non-blocking stack (Project Reactor, Mono/Flux), for high-concurrency or streaming workloads, runnable on Netty.
@RestController
class UserController {
  @GetMapping("/users/{id}")
  User get(@PathVariable Long id) { ... }
}

What it handles: routing requests to handlers, data binding and validation, content negotiation (JSON via Jackson), exception handling (@ExceptionHandler/@ControllerAdvice), and building RESTful APIs.

The 2026 detail interviewers like: choose MVC for typical blocking apps (now even cheaper to scale with Java virtual threads) and WebFlux when you need non-blocking concurrency end-to-end. For calling other services, modern Spring favors the new RestClient (and declarative @HttpExchange HTTP interfaces) over the legacy RestTemplate.

↑ Back to top

Follow-up 1

How does Spring handle web requests?

Spring handles web requests by using the DispatcherServlet. When a request is received, the DispatcherServlet acts as the front controller and delegates the request to the appropriate handler based on the request URL. The handler can be a controller method, a RESTful service, or any other component that can process the request. The DispatcherServlet also manages the execution flow, interceptors, and view resolution.

Follow-up 2

What is the role of the DispatcherServlet in Spring MVC?

The DispatcherServlet is the central component in the Spring MVC framework. Its role is to receive incoming requests, delegate them to the appropriate handler, and manage the overall request processing flow. The DispatcherServlet is responsible for handling request mapping, invoking controller methods, applying interceptors, and resolving views to render the response. It acts as the front controller in the MVC architecture.

Follow-up 3

How does Spring support RESTful web services?

Spring provides support for building RESTful web services through the use of the @RestController annotation. By annotating a class with @RestController, the class becomes a RESTful controller that can handle HTTP requests and produce JSON or XML responses. Spring also provides annotations such as @RequestMapping, @GetMapping, @PostMapping, etc., to define the URL mappings and HTTP methods for the RESTful endpoints. Additionally, Spring supports content negotiation, request validation, and exception handling for RESTful web services.

Follow-up 4

Can you explain how form handling is done in Spring MVC?

In Spring MVC, form handling is done by binding form data to a model object using the @ModelAttribute annotation. When a form is submitted, the form data is automatically bound to the model object based on the field names. The model object can then be processed by a controller method, which can perform validation, business logic, and database operations. Spring provides validation support through the use of annotations such as @Valid and @NotBlank. The result of the form processing can be displayed in a view using the model object.

5. How does the Test module in Spring support testing in a Spring application?

The Test module (spring-test) makes it easy to test Spring apps at every level by managing the ApplicationContext for tests, supporting dependency injection into tests, and providing mocks and helpers.

What it offers:

  • @SpringBootTest / @ContextConfiguration — load an application context (full or sliced) for integration tests, with context caching so it's reused across tests for speed.
  • Test slices (Boot) — @WebMvcTest, @DataJpaTest, @JsonTest load only the relevant layer for faster, focused tests.
  • MockMvc (and the newer MockMvcTester) / WebTestClient — test controllers and REST endpoints without a running server.
  • @MockitoBean/@MockitoSpyBean (modern replacements for @MockBean) — swap beans for mocks in the context.
  • Transactional tests@Transactional auto-rolls-back DB changes after each test; @Sql seeds data.
@WebMvcTest(UserController.class)
class UserControllerTest {
  @Autowired MockMvc mvc;
  @MockitoBean UserService service;   // mock in the context
}

The framing that signals current knowledge: combine plain JUnit 5 + Mockito for unit tests with Spring's slices for integration tests, and reach for Testcontainers to run real databases/brokers in integration tests — the modern standard over in-memory fakes.

↑ Back to top

Follow-up 1

What are the different types of testing supported by Spring?

Spring supports various types of testing, including:

  1. Unit Testing: Spring provides support for writing unit tests for individual components such as controllers, services, and repositories.

  2. Integration Testing: Spring allows developers to write integration tests to verify the interaction between different components of a Spring application.

  3. End-to-End Testing: Spring supports end-to-end testing by providing utilities to simulate user interactions and test the application as a whole.

Follow-up 2

How does Spring support integration testing?

Spring supports integration testing by providing a test context framework. The test context framework allows developers to create and configure a test context that mirrors the runtime context of a Spring application. This enables integration tests to run in an environment that closely resembles the actual application environment, including the configuration of beans, database connections, and other dependencies.

Follow-up 3

Can you explain the concept of a test context in Spring?

In Spring, a test context is a runtime context that is created specifically for running tests. It is a lightweight container that is used to configure and manage the beans required for testing. The test context is created based on the configuration provided by the developer, which can include XML configuration files, Java configuration classes, or a combination of both. The test context provides the necessary infrastructure for running tests, including dependency injection, transaction management, and other Spring features.

Follow-up 4

How does Spring provide mock objects for testing?

Spring provides support for creating mock objects for testing through the use of mock frameworks such as Mockito or EasyMock. These frameworks allow developers to create mock objects that simulate the behavior of real objects, allowing them to isolate the code being tested and control its dependencies. Spring integrates with these mock frameworks by providing annotations and utilities that simplify the process of creating and injecting mock objects into tests.

Live mock interview

Mock interview: Spring Architecture

Intermediate ~5 min Your own free AI key

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.