Java Omnibus
OOAD & Architecture / Reference & Downloads / GoF in Spring Framework
Reference Spring GoF Framework Patterns
Reference & Downloads

Spring becomes easier to reason about when you can see the classic pattern moves hiding inside the framework.

Spring is not a catalog of pure textbook patterns, but it uses many classic ideas repeatedly: Factory, Proxy, Strategy, Adapter, Template Method, Observer-style events, and more. This page maps those ideas to common Spring concepts so framework behavior feels more explainable.

Why This Topic Matters

Why it matters in real Java systems

Framework-driven Java development gets easier when teams can explain what the framework is doing instead of treating it as magic. Once you see proxies around transactions, strategies in pluggable resolvers, or templates in helper abstractions, the architecture becomes easier to debug and extend.

Core Explanation

The main reference idea

This page focuses on learning value, not on claiming one framework type equals one textbook pattern. Spring blends ideas pragmatically. The useful thing is seeing how these recurring shapes help the framework stay extensible and configurable.

Concept Breakdown

Key ideas to keep in mind

Reference

Proxy

Transactional and security behavior often arrive through proxies that wrap target beans.

Reference

Strategy

Resolvers, converters, handlers, and policies are often represented as interchangeable strategies.

Reference

Template

Template-style abstractions reduce repeated workflow code while allowing controlled variation.

Spring pattern mapping table

Spring pattern mapping table

Pattern idea Spring example Why it matters
ProxyTransactional AOP proxiesCross-cutting behavior wraps business components cleanly
FactoryBean factory and configuration methodsObject creation is managed and configurable
StrategyHandlerMethodArgumentResolver, converters, policiesFramework extension points stay pluggable
TemplateJdbcTemplate, earlier template abstractionsCommon workflow stays fixed while small steps vary
AdapterHandler adapters and integration adaptersDifferent components can participate behind common interfaces
Observer-style eventsApplication events and listenersLoose in-process signaling between components
Java Example

Java example in the Order Management domain

Java example: Spring-style strategy extension point
package org.javaomnibus.reference;

public interface OrderPricingPolicy {
    Money price(Order order);
}

public final class PromotionalOrderPricingPolicy implements OrderPricingPolicy {
    @Override
    public Money price(Order order) {
        return order.total().subtract(order.promotionalDiscount());
    }
}
Code Walkthrough

Step by step

  1. The code is plain Java, but it models the same pluggable strategy shape frameworks use extensively.
  2. Spring succeeds with these patterns because the extension contracts are explicit and repeatable.
  3. Seeing that makes framework behavior feel more teachable and less magical.
  4. That is the purpose of a reference page like this one.
Real-World Usage

Where this helps in practice

  • Teaching Spring internals through pattern language
  • Helping teams extend framework points more deliberately
  • Framework debugging and onboarding
Trade-Offs

Trade-offs and when to be careful

  • Pattern mapping improves comprehension, but it can oversimplify how large frameworks actually compose behavior.
  • The value is explanatory clarity, not taxonomic perfection.
Common Mistakes

Frequent mistakes to watch for

  • Treating framework abstractions as magic instead of designed extension points
  • Overgeneralizing one Spring feature into one perfect textbook pattern
  • Ignoring the runtime cost and debugging implications of proxy-based behavior
  • Using the framework without understanding what part owns the execution flow
Related Pages

Related concepts


What To Read Next