- Chapter
- Chapter 1 — Spring Framework Fundamentals
- Prerequisites
- Topic 1.2 (architecture); basic Maven/Gradle dependency management
- You will be able to
- Choose the right Spring artifacts for a workload, reason about transitive dependencies, and keep versions aligned
- Covers
- Core container · Data access · Web · Testing · Integration · Messaging · Security
On this page
- 1. Concept / Definition
- 2. Why It Exists
- 3. Core Concepts
- 4. How It Works Internally
- 4A. Deep Dive — Modules, JPMS and Boot Starters
- 5. APIs / Features / Syntax
- 6. Practical Examples
- 7. Common Problems & Mistakes
- 8. Performance & Production Considerations
- 9. Architecture & Design Considerations
- 10. Interview Questions & Answers
1Concept / Definition
A Spring module is an independently published JAR artifact (Maven group org.springframework) that packages one cohesive area of framework functionality — for example spring-jdbc for JDBC support or spring-webmvc for the Servlet web stack. Modules have explicit dependencies on each other and are always released together under one version number (for example 7.0.x).
Where Topic 1.2 described Spring's functional architecture, this topic describes its physical packaging: which JARs exist, what each contains, which ones depend on which, and how an application selects them. The TOC groups the modules into seven areas. Five of them (core container, data access, web, testing, messaging/integration basics) are Framework modules; security is delivered by the separate Spring Security project, and rich integration by Spring Integration.

2Why It Exists
- Smaller, focused deployments. A batch job that needs only DI and JDBC should not ship MVC, WebSocket and reactive libraries.
- Clear dependency direction. Modular packaging enforces the layering from Topic 1.2 at build time:
spring-corecannot accidentally depend onspring-webmvc. - Optional third-party integrations. Integrations (Hibernate, Jackson, Reactor, Quartz, Caffeine) are optional dependencies of Spring modules, so they activate only when the application itself adds them.
- Independent evolution of projects. Keeping Security, Data, Integration and others as separate projects lets them release on their own cadence while sharing the Framework's core.
3Core Concepts
3.1 Core container modules
| Artifact | Contains | Typical direct use |
|---|---|---|
spring-core | Utilities, Resource, conversion, annotation model, repackaged ASM/CGLIB/Objenesis | Never declared alone; transitive |
spring-beans | BeanFactory, BeanDefinition, BeanWrapper | Transitive |
spring-context | ApplicationContext, annotations config, events, scheduling, caching abstraction, validation integration, JMX, resilience (7.0) | The usual starting dependency |
spring-context-support | Adapters for third-party libraries: Caffeine and JCache caches, Quartz scheduling, FreeMarker, JavaMail (JavaMailSender) | When using those libraries |
spring-expression | SpEL | Transitive via context |
3.2 AOP and instrumentation modules
spring-aop— proxy-based AOP infrastructure, used by context and tx.spring-aspects— ready-made AspectJ aspects (for example@Configurablesupport, AspectJ-mode@Transactional).spring-instrument— a Java agent for load-time weaving where full AspectJ is required.
3.3 Data access modules
| Artifact | Purpose | Key types |
|---|---|---|
spring-tx | Transaction abstraction and DataAccessException hierarchy | PlatformTransactionManager, @Transactional, TransactionTemplate |
spring-jdbc | JDBC support, embedded databases, SQL exception translation | JdbcClient, JdbcTemplate, DataSourceTransactionManager |
spring-orm | JPA / Hibernate integration | LocalContainerEntityManagerFactoryBean, JpaTransactionManager |
spring-r2dbc | Reactive relational access | DatabaseClient, R2dbcTransactionManager |
spring-oxm | Object/XML mapping abstraction | Marshaller, Unmarshaller (JAXB) |
3.4 Web modules
| Artifact | Purpose |
|---|---|
spring-web | Shared HTTP abstractions: message converters, RestClient, WebClient API contracts, HTTP interface clients, CORS, multipart, HttpHeaders |
spring-webmvc | Servlet-based MVC: DispatcherServlet, annotated controllers, view technologies, functional endpoints |
spring-webflux | Reactive web on Reactor with Netty or Servlet containers; WebClient implementation |
spring-websocket | WebSocket and STOMP messaging for Servlet applications |
3.5 Testing module
spring-test provides the TestContext framework (@SpringJUnitConfig, @ContextConfiguration, context caching across test classes), MockMvc, WebTestClient, RestTestClient (new in Framework 7 for testing any server, including live servers, with a fluent API), mock Servlet API objects, @Sql scripts, and @MockitoBean/@MockitoSpyBean for replacing beans in a test context. It is declared with test scope.
3.6 Integration and messaging modules
spring-messaging— the generic messaging model:Message<T>,MessageChannel,@MessageMapping, STOMP support. It is the foundation for WebSocket messaging, Spring Integration and Spring Cloud Stream.spring-jms— JMS 3.1 (Jakarta Messaging) support:JmsTemplate, the new fluentJmsClientin Framework 7,@JmsListenerand listener containers.- Scheduling, remoting-free integrations and JMX live in
spring-context. - The separate Spring Integration, Spring AMQP (RabbitMQ) and Spring for Apache Kafka projects provide richer integration and broker-specific support.
3.7 Security
There is no spring-security module inside the Framework. Security comes from the Spring Security project, whose own artifacts (spring-security-core, -web, -config, -oauth2-client, -oauth2-resource-server, -oauth2-jose, -saml2-service-provider) sit on top of Framework modules. Keep this distinction clear: Spring Security versions are aligned with the Framework through Spring Boot's dependency management rather than sharing its version number.
4How It Works Internally
4.1 The module dependency graph

Each module declares its required dependencies in its POM. Declaring a high-level module transitively brings in the layers below it. Integrations with third-party libraries are declared as optional dependencies, so they are not pulled into your application unless you add the library yourself — Spring then detects it on the classpath (for example, Jackson for JSON conversion).
4.2 Classpath detection
Many Spring features switch on when a class is present. spring-web registers a JSON message converter only if a Jackson ObjectMapper class is found; Spring Boot generalises this with @ConditionalOnClass. Understanding this is essential for diagnosing "why is this feature active?" questions.
// Simplified from spring-web: decides converters by classpath presence
static {
ClassLoader cl = WebMvcConfigurationSupport.class.getClassLoader();
jackson2Present = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", cl);
// Framework 7 additionally detects Jackson 3 (tools.jackson.databind.json.JsonMapper)
}4.3 Version alignment through the BOM
All Framework modules share one version. The spring-framework-bom (bill of materials) pins them so that you declare the version once. Spring Boot's dependency management goes further, aligning Framework, Data, Security, Micrometer, Jackson, Hibernate and hundreds of third-party libraries.
<!-- Maven: import the Framework BOM, then omit versions on modules -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>7.0.0</version> <!-- use the latest 7.0.x patch -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId></dependency>
<dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><scope>test</scope></dependency>
</dependencies>4ADeep Dive — Modules, JPMS and Boot Starters
Automatic module names. Spring Framework JARs declare an Automatic-Module-Name in their manifests (for example spring.context) so that they can be placed on the Java module path, but they are not full JPMS modules with module-info.class. Most Spring applications run on the classpath; if you use JPMS, you must open your packages to Spring for reflection:
module com.acme.billing {
requires spring.context;
requires spring.jdbc;
opens com.acme.billing to spring.core, spring.beans, spring.context; // reflection access
}Framework modules vs Boot starters. A Spring Boot starter is not a Framework module. It is a curated dependency descriptor that bundles Framework modules, third-party libraries and auto-configuration. In Spring Boot 4, auto-configuration itself was split into smaller, technology-specific modules, and starters were reorganised to match, which reduces the amount of unused auto-configuration on a typical classpath.
| Aspect | Framework module | Boot starter |
|---|---|---|
| Example | spring-webmvc | spring-boot-starter-webmvc (Boot 4 naming; -web in Boot 3) |
| Contains code? | Yes — framework classes | Mostly none — a POM of dependencies |
| Brings a server? | No | Yes — embedded Tomcat by default |
| Brings configuration? | No — you configure | Yes — auto-configuration activated by conditions |
| Versioning | Framework version (7.0.x) | Boot version (4.0.x) managing all others |
5APIs / Features / Syntax
| Need | Minimal artifacts (Framework only) | Boot 4 equivalent |
|---|---|---|
| DI + scheduling | spring-context | spring-boot-starter |
| JDBC + transactions | spring-context, spring-jdbc (brings spring-tx) | spring-boot-starter-jdbc |
| JPA | spring-orm, spring-jdbc, Hibernate ORM | spring-boot-starter-data-jpa |
| REST API (Servlet) | spring-webmvc + Jackson + Servlet container | spring-boot-starter-webmvc |
| Reactive web | spring-webflux + Reactor Netty | spring-boot-starter-webflux |
| JMS | spring-jms + JMS client | spring-boot-starter-artemis (or broker-specific) |
| Caching with Caffeine | spring-context-support + Caffeine | spring-boot-starter-cache + Caffeine |
| Testing | spring-test + JUnit Jupiter + AssertJ + Mockito | spring-boot-starter-test |

6Practical Examples
6.1 Gradle: a JDBC batch worker without Boot
// build.gradle.kts
dependencies {
implementation(platform("org.springframework:spring-framework-bom:7.0.0"))
implementation("org.springframework:spring-context")
implementation("org.springframework:spring-jdbc")
runtimeOnly("org.postgresql:postgresql:42.7.4")
testImplementation("org.springframework:spring-test")
testImplementation("org.junit.jupiter:junit-jupiter")
}6.2 Inspecting what a module pulls in
# Maven: show the resolved tree for spring-webmvc
mvn dependency:tree -Dincludes=org.springframework
# [INFO] +- org.springframework:spring-webmvc:jar:7.0.x
# [INFO] | +- org.springframework:spring-aop:jar:7.0.x
# [INFO] | +- org.springframework:spring-beans:jar:7.0.x
# [INFO] | +- org.springframework:spring-context:jar:7.0.x
# [INFO] | +- org.springframework:spring-core:jar:7.0.x
# [INFO] | +- org.springframework:spring-expression:jar:7.0.x
# [INFO] | \- org.springframework:spring-web:jar:7.0.x6.3 A slice test using only spring-test
@SpringJUnitConfig(BillingConfig.class) // TestContext framework; context cached across classes
@Sql("/schema.sql")
class InvoiceRepositoryIT {
@Autowired InvoiceRepository repo;
@Test
void savesInvoice() {
repo.save(new Invoice(1L, new BigDecimal("10.00")));
assertThat(repo.count()).isEqualTo(1);
}
}7Common Problems & Mistakes
- Mixed module versions. Declaring
spring-context:7.0.1andspring-jdbc:6.2.xleads toNoSuchMethodError/ClassNotFoundExceptionat runtime. Always use the BOM or Boot's dependency management. - Overriding Boot-managed versions casually. Forcing a newer Framework patch under Boot is usually fine, but forcing a different minor version breaks the tested combination.
- Adding Jackson 2 and 3 accidentally. Framework 7/Boot 4 default to Jackson 3 (
tools.jacksonpackages) with Jackson 2 support deprecated; having both on the classpath can cause surprising converter selection. - Forgetting
spring-context-support. Using Caffeine or JavaMail support without it producesClassNotFoundExceptionfor the Spring adapter classes. - Expecting
spring-securityfrom the Framework BOM. Security artifacts are managed by Spring Security's own BOM or by Boot. - Shipping
spring-testto production. Scope it astest.
8Performance & Production Considerations
| Concern | Why it matters | Practice |
|---|---|---|
| Classpath size | More JARs mean more scanning, larger images and wider vulnerability surface | Remove unused modules; audit with dependency:analyze |
| Conditional activation | Unused libraries on the classpath can activate features (Boot) | Exclude transitive libraries you do not want active |
| Security patching | Framework CVEs are fixed in patch releases | Track 7.0.x patches; rely on BOM so one property upgrades everything |
| Container images | Layered JARs let unchanged dependencies be cached | Boot's layered JAR/buildpacks separate dependencies from application code |
| Native images | Every module adds reachability metadata | Keep the module set lean for GraalVM builds |
9Architecture & Design Considerations
- Match modules to architectural layers. A domain module should depend on nothing from Spring (or at most
spring-contextfor stereotypes); adapters depend onspring-jdbc,spring-webmvc, etc. This makes dependency direction visible in the build files. - Standardise via a platform BOM. Large organisations publish an internal BOM that imports Spring Boot's dependency management plus approved internal libraries, giving every service the same tested versions.
- Prefer Boot unless there is a reason not to. Plain Framework modules make sense for libraries, embedded use in non-Spring hosts, or teams that need precise control; for services, Boot's curated combinations reduce upgrade risk.
- Plan major upgrades as programmes. Framework 6→7 involves Jakarta EE 11, Jackson 3, JSpecify and removed APIs — treat it as a tracked migration with automated tooling (e.g., OpenRewrite recipes).
10Interview Questions & Answers
Which Spring module do you normally start with for a dependency-injection application?
spring-context is the usual starting point, because it is the module that contains ApplicationContext and everything most applications expect from a container. Declaring it brings spring-beans, spring-core, spring-aop and spring-expression transitively, so you get bean definitions and creation, the resource and conversion utilities, proxy infrastructure for features such as @Transactional, and SpEL for @Value expressions. On top of that, spring-context itself adds annotation configuration with @Configuration and @ComponentScan, events, Environment and profiles, scheduling, the caching abstraction and validation integration. You add spring-context-support only if you need adapters for Caffeine, Quartz or JavaMail. With Boot, spring-boot-starter brings spring-context for you, along with logging and auto-configuration.
What does spring-test provide?
spring-test is the Framework's testing module, declared with test scope, and its core is the TestContext framework. That framework loads an ApplicationContext for a test class from @SpringJUnitConfig or @ContextConfiguration and caches it by configuration key, so later test classes with the same setup reuse it instead of starting again, which is what keeps large integration suites fast. It also provides transactional tests that roll back by default, @Sql for running schema and data scripts, and @MockitoBean and @MockitoSpyBean for replacing beans. For the web tier it offers MockMvc and MockMvcTester, WebTestClient, the new RestTestClient in Framework 7, and mock Servlet API objects. Boot's test starter builds its slices on top of it.
What is the purpose of spring-framework-bom?
It is a Maven bill of materials that lists every Spring Framework module at the same version, so you import it once in dependencyManagement, or as a Gradle platform, and then declare spring-context, spring-jdbc and the rest without versions. Its real value is preventing version drift. Framework modules are released together and call each other's internal APIs, so mixing spring-context 7.0.1 with spring-jdbc 6.2 compiles but fails at runtime with NoSuchMethodError or ClassNotFoundException, often only on a rarely used path. The BOM also turns an upgrade into a one-line change. It covers Framework modules only; Spring Boot's spring-boot-dependencies goes further and aligns Security, Data, Jackson, Hibernate and hundreds of other libraries.
What is the difference between spring-web and spring-webmvc?
spring-web contains the HTTP abstractions that do not depend on a particular server programming model: HttpHeaders and MediaType, HttpMessageConverters, multipart and CORS support, the RestClient and WebClient API contracts and HTTP interface clients. It is shared by both server stacks and by pure client applications, so a batch job that only calls REST APIs needs spring-web but not spring-webmvc. spring-webmvc is the Servlet-based server framework built on top of it: DispatcherServlet, handler mappings and adapters, annotated controllers, functional endpoints and view resolution. spring-webflux is the reactive sibling, also built on spring-web. Knowing the split explains why a client-only application can call APIs without pulling in an MVC framework it never uses.
How does Spring activate JSON support without you configuring it?
Through optional dependencies and classpath detection. spring-web declares Jackson as an optional dependency, so the Framework compiles against Jackson but does not force it on you. When the MVC configuration is built, WebMvcConfigurationSupport checks with ClassUtils.isPresent whether Jackson classes are on the classpath; in Framework 7 it looks for Jackson 3's JsonMapper first and treats Jackson 2 as a deprecated fallback. If a match is found, it registers the corresponding HttpMessageConverter, and controllers can return objects that are written as JSON. Spring Boot generalises the pattern with @ConditionalOnClass and builds the mapper from spring.jackson properties. The practical consequence is that adding or removing a JAR changes behaviour, so check the dependency tree first.
How does a Boot starter differ from a Framework module?
A Framework module is a JAR of framework code, such as spring-webmvc, versioned with the Framework at 7.0.x, and it does nothing until you configure it. A starter, such as spring-boot-starter-webmvc in Boot 4, contains almost no code: it is a curated dependency descriptor that pulls in the Framework modules, third-party libraries such as Jackson and embedded Tomcat, and the Boot auto-configuration module for that technology, all at versions managed by the Boot release. So a starter brings opinions, such as an embedded server and default converters, that a module never does. In Boot 4 auto-configuration is split into technology-specific modules, so choosing starters carefully controls exactly which auto-configuration lands on the classpath.
How would you keep 60 microservices on consistent Spring dependency versions?
I would make version alignment a platform product rather than a per-team decision. A platform team publishes an internal BOM, or a parent, that imports spring-boot-dependencies and adds approved versions of internal libraries and common third-party ones, and every service inherits it, so no service declares Spring versions of its own. Renovate or Dependabot raises upgrade pull requests automatically, OpenRewrite recipes handle mechanical migrations, and CI enforces dependency convergence, rejects banned or duplicate artifacts and runs vulnerability scanning. A dashboard showing which BOM version each service uses makes laggards visible. Finally, I would define a support policy, such as staying within one minor release of current, so upgrades stay small and routine.
What risks do you assess when planning a Spring Framework 6 to 7 upgrade across a portfolio?
I would assess compatibility first, then sequencing. Framework 7 requires Jakarta EE 11, so servlet containers, JPA providers and Bean Validation must be at matching versions, and any library still on javax packages blocks the upgrade. Jackson 3 changes package names and some defaults, which affects custom serialisers and message formats. Support for javax.annotation and javax.inject is gone, JSpecify nullness annotations change Kotlin and static-analysis results, and removed APIs surface at compile time. In practice the upgrade arrives through Boot 4, so I would move services to the latest Boot 3.5 first, inventory third-party dependencies, pilot two representative services, automate refactoring with OpenRewrite, and schedule the portfolio within open-source support windows.
Test your knowledge on this topic →Flashcards from this topic's 8 questions, filtered by level and type.