Skip to content
Spring Boot sb design-patterns 3 min read

GoF Patterns in Spring — Reference

This page is a quick-lookup reference for the 23 Gang of Four (GoF) design patterns as they appear inside the Spring framework and the Spring Boot ecosystem. Each table covers one GoF category and maps every pattern to where Spring uses it and a concrete class or annotation you can go read. Use it as a cheat sheet; the dedicated pages in this section explain the headline patterns in depth.

Creational patterns

These govern how objects are created — Spring’s whole reason for existing as an IoC container.

PatternWhere Spring uses itExample class / annotation
SingletonDefault bean scope (one instance per context)@Component, @Scope("singleton")
Factory MethodProgrammatic bean creation@Bean method, FactoryBean#getObject
Abstract FactoryThe container that produces all beansBeanFactory, ApplicationContext
BuilderFluent construction of complex objectsUriComponentsBuilder, RestClient.builder(), Lombok @Builder
PrototypeFresh instance per lookup@Scope("prototype"), ObjectProvider#getObject

See Singleton, Factory & Abstract Factory, and Builder.

Structural patterns

These govern how objects are composed and how interfaces are bridged.

PatternWhere Spring uses itExample class / annotation
ProxyAOP cross-cutting concerns@Transactional, @Cacheable, @Async, JDK proxy / CGLIB
AdapterBridging handler & invocation stylesHandlerAdapter, HandlerInterceptorAdapter
DecoratorWrapping bean behavior at creationBeanPostProcessor, HttpServletRequestWrapper
FacadeSimplified API over subsystemsJmsTemplate, JdbcTemplate (also template method)
CompositeTreating groups uniformlyCompositeHandlerExceptionResolver, CompositeCacheManager
BridgeDecoupling abstraction from implJdbcTemplate over DataSource/Dialect
FlyweightShared immutable instancesInterned MediaType/HttpStatus constants

See Proxy Pattern & AOP and Front Controller (which uses adapter and decorator internally).

Behavioral patterns

These govern how objects interact and distribute responsibility.

PatternWhere Spring uses itExample class / annotation
Template MethodBoilerplate-free resource accessJdbcTemplate, RestTemplate, TransactionTemplate
StrategyInterchangeable pluggable behaviorPasswordEncoder, HandlerMethodArgumentResolver, HttpMessageConverter
ObserverDecoupled event notificationApplicationEventPublisher, @EventListener, @TransactionalEventListener
Chain of ResponsibilitySequential request processingServlet Filter chain, HandlerInterceptor chain, Spring Security FilterChain
CommandEncapsulated unit of workRunnable/Callable via TaskExecutor, @Scheduled tasks
IteratorTraversing result sets / pagesPageable/Slice, repository Stream results
MediatorCoordinating collaboratorsDispatcherServlet orchestrating MVC components
StateLifecycle phase handlingBean lifecycle (InitializingBean, SmartLifecycle)
VisitorOperating over a structureBeanDefinitionVisitor, TypeFilter
InterpreterEvaluating an expression grammarSpring Expression Language (SpEL)

See Template Method, Strategy, and Observer & Events.

At-a-glance: the headline mappings

If you remember nothing else, remember these five — they account for the bulk of day-to-day Spring:

You write……and Spring appliesCovered in
Constructor-injected @ServiceDependency Injection (IoC)DI & IoC
@Transactional / @CacheableProxyProxy & AOP
jdbc.query(sql, mapper)Template MethodTemplate Method
List<Strategy> injectionStrategyStrategy
publishEvent(...) + @EventListenerObserverObserver

Note: Many Spring classes embody more than one pattern at once. JdbcTemplate, for instance, is a template method (it owns the algorithm skeleton) and a facade (it simplifies the JDBC subsystem). Patterns are lenses, not boxes — a single class can be viewed through several.

Tip: When reading Spring source, the class name is often the clearest hint: a *Template is template-method, a *Builder is builder, a *Factory/*FactoryBean is a factory, a *Adapter is adapter, and a *Resolver/*Strategy is almost always strategy.

For the language-level explanation of each pattern with plain-Java examples — and the difference between, say, JDK proxies and a hand-written proxy class — see the companion page below.

Last updated June 13, 2026
Was this helpful?