<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Spring on Java &amp; Software Architecture Knowledge Hub</title><link>https://samirsahoo.github.io/design-patterns-hub/tags/spring/</link><description>Recent content in Spring on Java &amp; Software Architecture Knowledge Hub</description><generator>Hugo</generator><language>en-US</language><copyright>© 2026 Samir Kumar Sahoo (https://github.com/samirsahoo). All rights reserved.</copyright><atom:link href="https://samirsahoo.github.io/design-patterns-hub/tags/spring/index.xml" rel="self" type="application/rss+xml"/><item><title>Dependency Injection in Java</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/dependency-injection/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/dependency-injection/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Dependency injection (DI)&lt;/strong&gt; means an object receives the objects it works with — its &lt;em&gt;dependencies&lt;/em&gt; — from outside, instead of creating or looking them up itself.&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-java" data-lang="java"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// Without DI: the service decides which notifier it uses.&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;private&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;final&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Notifier&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;notifier&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;EmailNotifier&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="c1"&gt;// With DI: whoever creates the service decides.&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="kd"&gt;public&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;OrderService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Notifier&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;notifier&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;notifier&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That is the entire idea. Frameworks such as Spring automate the wiring, but DI itself needs no framework.&lt;/p&gt;</description></item><item><title>Spring MVC Architecture: DispatcherServlet, Handler Mappings and Controllers</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/web/spring-mvc-architecture/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/web/spring-mvc-architecture/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Spring MVC&lt;/strong&gt; is Spring&amp;rsquo;s servlet-based web framework. One servlet, the &lt;strong&gt;&lt;code&gt;DispatcherServlet&lt;/code&gt;&lt;/strong&gt; (a &lt;em&gt;front controller&lt;/em&gt;), receives every request and delegates to pluggable components. They find the right controller method, convert input, call it and write the response.&lt;/p&gt;</description></item><item><title>Inversion of Control: ApplicationContext and BeanFactory</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/applicationcontext-and-beanfactory/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/applicationcontext-and-beanfactory/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Inversion of Control (IoC)&lt;/strong&gt; means your objects do not create or look up their collaborators: a &lt;strong&gt;container&lt;/strong&gt; creates them, wires them and manages their lifecycle. In Spring, that container is the &lt;strong&gt;&lt;code&gt;ApplicationContext&lt;/code&gt;&lt;/strong&gt;, built on the lower-level &lt;strong&gt;&lt;code&gt;BeanFactory&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>RESTful API Design and Global Exception Handling</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/web/rest-api-design-and-error-handling/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/web/rest-api-design-and-error-handling/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;RESTful API&lt;/strong&gt; exposes &lt;strong&gt;resources&lt;/strong&gt; (orders, customers) at stable URIs and uses &lt;strong&gt;HTTP methods and status codes&lt;/strong&gt; with their standard meanings. &lt;strong&gt;Global exception handling&lt;/strong&gt; turns every error into a &lt;strong&gt;consistent, machine-readable response&lt;/strong&gt;, in Spring using &lt;code&gt;@RestControllerAdvice&lt;/code&gt; and &lt;strong&gt;RFC 9457 Problem Details&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Bean Lifecycle and Scopes</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/bean-lifecycle-and-scopes/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/bean-lifecycle-and-scopes/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;bean lifecycle&lt;/strong&gt; is the sequence of steps Spring performs to create, initialise, use and destroy a bean. A bean&amp;rsquo;s &lt;strong&gt;scope&lt;/strong&gt; decides &lt;strong&gt;how many instances&lt;/strong&gt; exist and &lt;strong&gt;how long&lt;/strong&gt; each lives.&lt;/p&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Opening connections in a constructor before properties are injected, forgetting to close thread pools on shutdown, or storing per-user data in a singleton are common, serious bugs. Knowing the lifecycle tells you &lt;strong&gt;where&lt;/strong&gt; code belongs; knowing scopes tells you what is &lt;strong&gt;shared&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Spring WebFlux and Reactive Programming with Project Reactor</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/web/webflux-and-reactive-programming/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/web/webflux-and-reactive-programming/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Reactive programming&lt;/strong&gt; composes &lt;strong&gt;asynchronous, non-blocking streams of data&lt;/strong&gt; with &lt;strong&gt;backpressure&lt;/strong&gt;, so a consumer controls how fast data arrives. &lt;strong&gt;Project Reactor&lt;/strong&gt; implements it with two types: &lt;strong&gt;&lt;code&gt;Mono&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/strong&gt; (0 or 1 item) and &lt;strong&gt;&lt;code&gt;Flux&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/strong&gt; (0 to N items). &lt;strong&gt;Spring WebFlux&lt;/strong&gt; is the reactive web framework built on Reactor, usually running on &lt;strong&gt;Netty&lt;/strong&gt; with a small number of event-loop threads.&lt;/p&gt;</description></item><item><title>Spring Configuration: @Configuration, @Bean, Component Scanning and Profiles</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/configuration-and-component-scanning/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/configuration-and-component-scanning/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Spring learns &lt;strong&gt;which beans to create&lt;/strong&gt; in three main ways:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&lt;strong&gt;Component scanning&lt;/strong&gt;: annotate your classes (&lt;code&gt;@Component&lt;/code&gt;, &lt;code&gt;@Service&lt;/code&gt; and so on) and Spring finds them.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Java configuration&lt;/strong&gt;: &lt;code&gt;@Bean&lt;/code&gt; factory methods inside &lt;code&gt;@Configuration&lt;/code&gt; classes, ideal for third-party classes you cannot annotate.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Auto-configuration&lt;/strong&gt;: Spring Boot&amp;rsquo;s conditional defaults. See &lt;a href="https://samirsahoo.github.io/design-patterns-hub/spring/boot/auto-configuration-and-conditions/"&gt;auto-configuration&lt;/a&gt;.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Without a clear configuration strategy, applications end up with duplicate beans, surprising overrides, beans scanned from the wrong packages, and environment-specific code paths scattered everywhere.&lt;/p&gt;</description></item><item><title>Database Transactions in Spring: @Transactional, Propagation and Isolation</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/transactions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/transactions/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;transaction&lt;/strong&gt; groups database operations so they &lt;strong&gt;all succeed or all fail&lt;/strong&gt; (ACID). In Spring you declare transaction boundaries with &lt;strong&gt;&lt;code&gt;@Transactional&lt;/code&gt;&lt;/strong&gt;. A proxy then begins, commits or rolls back through a &lt;strong&gt;&lt;code&gt;PlatformTransactionManager&lt;/code&gt;&lt;/strong&gt; (for example &lt;code&gt;JpaTransactionManager&lt;/code&gt;).&lt;/p&gt;</description></item><item><title>Spring Cache Abstraction and Redis Integration</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/caching/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/caching/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Spring Cache abstraction&lt;/strong&gt; lets you cache method results declaratively with &lt;code&gt;@Cacheable&lt;/code&gt; and friends. &lt;strong&gt;Where&lt;/strong&gt; data is cached is pluggable: &lt;strong&gt;Caffeine&lt;/strong&gt; in local memory, &lt;strong&gt;Redis&lt;/strong&gt; (or Valkey) shared across instances, Hazelcast and others.&lt;/p&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Repeated expensive calls (database aggregations, remote price lookups, reference data) waste latency and load. Ad-hoc &lt;code&gt;Map&lt;/code&gt; caches have no eviction or TTL, are not shared, and are scattered through the code.&lt;/p&gt;</description></item><item><title>Spring Expression Language (SpEL)</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/spring-expression-language/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/spring-expression-language/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;SpEL (Spring Expression Language)&lt;/strong&gt; is a small expression language that Spring evaluates &lt;strong&gt;at runtime&lt;/strong&gt; against objects, beans and context. It powers dynamic values in annotations such as &lt;code&gt;@Value(&amp;quot;#{…}&amp;quot;)&lt;/code&gt;, &lt;code&gt;@PreAuthorize(&amp;quot;…&amp;quot;)&lt;/code&gt;, &lt;code&gt;@Cacheable(key = &amp;quot;…&amp;quot;)&lt;/code&gt; and &lt;code&gt;@EventListener(condition = &amp;quot;…&amp;quot;)&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Aspect-Oriented Programming (AOP), Advice Types and Proxies</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/aop-and-proxies/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/aop-and-proxies/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Aspect-oriented programming (AOP)&lt;/strong&gt; keeps &lt;strong&gt;cross-cutting concerns&lt;/strong&gt; (logging, transactions, security, metrics, retries, caching) out of business code. You write the concern once as an &lt;strong&gt;aspect&lt;/strong&gt; and declare &lt;strong&gt;where&lt;/strong&gt; it applies. Spring AOP applies aspects by wrapping beans in &lt;strong&gt;proxies&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Spring Application Events and Listeners</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/core/application-events/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/core/application-events/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Spring&amp;rsquo;s &lt;strong&gt;application events&lt;/strong&gt; let one bean &lt;strong&gt;publish&lt;/strong&gt; a message (&amp;ldquo;an order was placed&amp;rdquo;) and any number of other beans &lt;strong&gt;listen&lt;/strong&gt; and react, without the publisher knowing them. It is the Observer pattern, implemented by the &lt;code&gt;ApplicationContext&lt;/code&gt;, &lt;strong&gt;inside one application&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Proxy Pattern</title><link>https://samirsahoo.github.io/design-patterns-hub/design-patterns/structural/proxy/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/design-patterns/structural/proxy/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;The &lt;strong&gt;Proxy&lt;/strong&gt; pattern puts a &lt;strong&gt;stand-in object&lt;/strong&gt; in front of a real object. The proxy implements the same interface, so clients cannot tell the difference, and it decides when and whether to forward each call: creating the real object lazily, checking permissions, caching results or calling across a network.&lt;/p&gt;</description></item></channel></rss>