ArchitectMind
  1. Home
  2. Java Ecosystem
  3. Book 4 · Spring & Spring Boot
  4. Volume I
  5. Spring Modules
Book 4 · Volume I — Spring Core, IoC & Dependency Injection · Topic 1.3

Spring Modules

How the Spring Framework is packaged into modules — core container, data access, web, testing, integration, messaging and security

11 min readStage 2 · Frameworks & design8 interview questions
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. 1. Concept / Definition
  2. 2. Why It Exists
  3. 3. Core Concepts
  4. 4. How It Works Internally
  5. 4A. Deep Dive — Modules, JPMS and Boot Starters
  6. 5. APIs / Features / Syntax
  7. 6. Practical Examples
  8. 7. Common Problems & Mistakes
  9. 8. Performance & Production Considerations
  10. 9. Architecture & Design Considerations
  11. 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.

Spring Framework 7 module groups
Figure 1 — Spring Framework 7 module groups

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-core cannot accidentally depend on spring-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

ArtifactContainsTypical direct use
spring-coreUtilities, Resource, conversion, annotation model, repackaged ASM/CGLIB/ObjenesisNever declared alone; transitive
spring-beansBeanFactory, BeanDefinition, BeanWrapperTransitive
spring-contextApplicationContext, annotations config, events, scheduling, caching abstraction, validation integration, JMX, resilience (7.0)The usual starting dependency
spring-context-supportAdapters for third-party libraries: Caffeine and JCache caches, Quartz scheduling, FreeMarker, JavaMail (JavaMailSender)When using those libraries
spring-expressionSpELTransitive via context
Table 1 — Core container artifacts

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 @Configurable support, AspectJ-mode @Transactional).
  • spring-instrument — a Java agent for load-time weaving where full AspectJ is required.

3.3 Data access modules

ArtifactPurposeKey types
spring-txTransaction abstraction and DataAccessException hierarchyPlatformTransactionManager, @Transactional, TransactionTemplate
spring-jdbcJDBC support, embedded databases, SQL exception translationJdbcClient, JdbcTemplate, DataSourceTransactionManager
spring-ormJPA / Hibernate integrationLocalContainerEntityManagerFactoryBean, JpaTransactionManager
spring-r2dbcReactive relational accessDatabaseClient, R2dbcTransactionManager
spring-oxmObject/XML mapping abstractionMarshaller, Unmarshaller (JAXB)
Table 2 — Data access artifacts

3.4 Web modules

ArtifactPurpose
spring-webShared HTTP abstractions: message converters, RestClient, WebClient API contracts, HTTP interface clients, CORS, multipart, HttpHeaders
spring-webmvcServlet-based MVC: DispatcherServlet, annotated controllers, view technologies, functional endpoints
spring-webfluxReactive web on Reactor with Netty or Servlet containers; WebClient implementation
spring-websocketWebSocket and STOMP messaging for Servlet applications
Table 3 — Web artifacts

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 fluent JmsClient in Framework 7, @JmsListener and 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

Simplified dependency graph between Framework modules
Figure 2 — Simplified dependency graph between Framework modules

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.

JAVA
// 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.

XML
<!-- 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:

JAVA
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.

AspectFramework moduleBoot starter
Examplespring-webmvcspring-boot-starter-webmvc (Boot 4 naming; -web in Boot 3)
Contains code?Yes — framework classesMostly none — a POM of dependencies
Brings a server?NoYes — embedded Tomcat by default
Brings configuration?No — you configureYes — auto-configuration activated by conditions
VersioningFramework version (7.0.x)Boot version (4.0.x) managing all others
Table 4 — Framework modules compared with Boot starters

5APIs / Features / Syntax

NeedMinimal artifacts (Framework only)Boot 4 equivalent
DI + schedulingspring-contextspring-boot-starter
JDBC + transactionsspring-context, spring-jdbc (brings spring-tx)spring-boot-starter-jdbc
JPAspring-orm, spring-jdbc, Hibernate ORMspring-boot-starter-data-jpa
REST API (Servlet)spring-webmvc + Jackson + Servlet containerspring-boot-starter-webmvc
Reactive webspring-webflux + Reactor Nettyspring-boot-starter-webflux
JMSspring-jms + JMS clientspring-boot-starter-artemis (or broker-specific)
Caching with Caffeinespring-context-support + Caffeinespring-boot-starter-cache + Caffeine
Testingspring-test + JUnit Jupiter + AssertJ + Mockitospring-boot-starter-test
Table 5 — Mapping workload needs to artifacts
Growing the module set incrementally
Figure 3 — Growing the module set incrementally

6Practical Examples

6.1 Gradle: a JDBC batch worker without Boot

KOTLIN
// 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

BASH
# 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.x

6.3 A slice test using only spring-test

JAVA
@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.1 and spring-jdbc:6.2.x leads to NoSuchMethodError/ClassNotFoundException at 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.jackson packages) 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 produces ClassNotFoundException for the Spring adapter classes.
  • Expecting spring-security from the Framework BOM. Security artifacts are managed by Spring Security's own BOM or by Boot.
  • Shipping spring-test to production. Scope it as test.

8Performance & Production Considerations

ConcernWhy it mattersPractice
Classpath sizeMore JARs mean more scanning, larger images and wider vulnerability surfaceRemove unused modules; audit with dependency:analyze
Conditional activationUnused libraries on the classpath can activate features (Boot)Exclude transitive libraries you do not want active
Security patchingFramework CVEs are fixed in patch releasesTrack 7.0.x patches; rely on BOM so one property upgrades everything
Container imagesLayered JARs let unchanged dependencies be cachedBoot's layered JAR/buildpacks separate dependencies from application code
Native imagesEvery module adds reachability metadataKeep the module set lean for GraalVM builds
Table 6 — Operational impact of module selection

9Architecture & Design Considerations

  • Match modules to architectural layers. A domain module should depend on nothing from Spring (or at most spring-context for stereotypes); adapters depend on spring-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

Q1L1 · BasicConcept

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.

Q2L1 · BasicConcept

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.

Q3L2 · IntermediateConcept

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.

Q4L2 · IntermediateConcept

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.

Q5L3 · Senior EngineerInternals

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.

Q6L3 · Senior EngineerTricky

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.

Q7L4 · Technical ArchitectDesign

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.

Q8L5 · Solution ArchitectScenario

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.

Free question pack

Get 100 free Core Java interview questions

Subscribe for the Book 1 question pack (PDF, every answer explained) and new tutorials once a week. No spam, unsubscribe anytime. What is in the pack?

Almost done! Check your inbox and click the confirmation link. Your download link arrives as soon as you confirm.