<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="/static/feed.xsl" type="text/xsl" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:quartz="https://quartz.jzhao.xyz/ns">
  <script xmlns="http://www.w3.org/1999/xhtml" src="/static/scripts/xslt-polyfill-214fd525.js"></script>
  <title>/wiki / java3</title>
  <subtitle>Recent notes in /wiki / java3 on Animesh Mishra</subtitle>
  <link href="https://animishraa05.github.io/wiki/java3" />
  <link rel="alternate" type="text/html" href="https://animishraa05.github.io/wiki/java3" />
  <category term="wiki/java3" />
  <id>https://animishraa05.github.io/wiki/java3</id>
  <updated>2026-09-02T00:00:00.000Z</updated>
  <contributor>
    <name>Animesh Mishra</name>
    <email>animesh.mishra818@gmail.com</email>
  </contributor>
  <logo>https://animishraa05.github.io/icon.png</logo>
  <icon>https://animishraa05.github.io/icon.png</icon>
  <generator>Quartz v4.6.0 -- quartz.jzhao.xyz</generator>
  <rights type="html">&amp;amp;copy; 2026 Animesh Mishra</rights>
  
  <entry>
    <title>ejb-container</title>
    <link href="https://animishraa05.github.io/wiki/java3/ejb-container" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/ejb-container.md" />
    <summary>The Problem Auto-created stub for broken link [[ejb-container]] — needs human content.</summary>
    <published>2026-09-02T00:00:00.000Z</published>
    <updated>2026-09-02T00:00:00.000Z</updated>
    <publishedTime>Sep 02, 2026</publishedTime>
    <updatedTime>Sep 02, 2026</updatedTime>
    <category term="dev" label="dev" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Auto-created stub for broken link &lt;code class=&quot;notranslate&quot;&gt;[[ejb-container]]&lt;/code&gt; — needs human content.&lt;/p&gt;
&lt;h2 id=&quot;formal-definition&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Formal Definition&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#formal-definition&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Per Wikipedia: “To be written.”&lt;/p&gt;
&lt;h2 id=&quot;explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Stub — fill with plain language explanation.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;To be written.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph ejb-container {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=LR&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  A [label=&quot;Stub: ejb-container&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B [label=&quot;To be written&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  A -&gt; B [label=&quot;needs content&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;graph semantic_ejb-container {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  layout=neato&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=ellipse fontname=&quot;Helvetica&quot; fontsize=11 style=filled]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS [label=&quot;ejb container&quot; fillcolor=&quot;#ffd700&quot; fontsize=13 style=&quot;filled,bold&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REL1 [label=&quot;Related&quot; fillcolor=&quot;#f0f0f0&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  THIS -- REL1 [label=&quot;related&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;To be written.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;real-world-example&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Real-World Example&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#real-world-example&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;python&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;# &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;TODO&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;: add example&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../&quot; class=&quot;internal alias&quot; data-slug=&quot;index&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Index&lt;/a&gt; — auto stub, needs proper links&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;To be written.&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Java3 — Map of Content</title>
    <link href="https://animishraa05.github.io/wiki/java3/java3-moc" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/java3-moc.md" />
    <summary> Map of Content for Java3 — 44 concepts. Start here to navigate java3.</summary>
    <published>2026-09-02T00:00:00.000Z</published>
    <updated>2026-09-02T00:00:00.000Z</updated>
    <publishedTime>Sep 02, 2026</publishedTime>
    <updatedTime>Sep 02, 2026</updatedTime>
    <category term="meta" label="meta" />
<category term="java3" label="java3" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;blockquote&gt;
&lt;p dir=&quot;auto&quot;&gt;Map of Content for &lt;strong&gt;Java3&lt;/strong&gt; — 44 concepts. Start here to navigate java3.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;core-concepts&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Concepts&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-concepts&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../api-gateway-pattern&quot; class=&quot;internal alias&quot; data-slug=&quot;api-gateway-pattern&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;API Gateway Pattern&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../dispatcher-servlet&quot; class=&quot;internal alias&quot; data-slug=&quot;dispatcher-servlet&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DispatcherServlet&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../distributed-tracing&quot; class=&quot;internal alias&quot; data-slug=&quot;distributed-tracing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Distributed Tracing&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hibernate-annotations&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-annotations&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Annotations&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hibernate-caching&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-caching&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Caching&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hibernate-entity-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-entity-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Entity Mapping&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../hql&quot; class=&quot;internal alias&quot; data-slug=&quot;hql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Query Language&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../jpa-pagination-sorting&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-pagination-sorting&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Pagination and Sorting&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../jpa-query-methods&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-query-methods&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Query Methods&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../jpa-repository&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-repository&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JpaRepository&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../junit-annotations-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-annotations-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Annotations and Lifecycle&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../junit-parameterized-tests&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-parameterized-tests&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Parameterized Tests&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../junit-testing&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-testing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Testing&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../monolithic-vs-microservices&quot; class=&quot;internal&quot; data-slug=&quot;monolithic-vs-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;monolithic-vs-microservices&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../service-discovery-registry&quot; class=&quot;internal alias&quot; data-slug=&quot;service-discovery-registry&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Service Discovery and Registry&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../servlet-vs-jsp&quot; class=&quot;internal&quot; data-slug=&quot;servlet-vs-jsp&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;servlet-vs-jsp&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-annotations&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-annotations&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Annotations&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-aop-advice&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-aop-advice&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring AOP Advice Types&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-aop&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-aop&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring AOP&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-autowiring&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-autowiring&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Autowiring&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-bean-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-bean-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Bean Lifecycle&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-boot-actuator&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-actuator&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Actuator&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-boot-auto-configuration&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-auto-configuration&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Auto-Configuration&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-boot-rest-api&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-rest-api&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot REST API&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-cloud-api-gateway&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-api-gateway&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud API Gateway&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-cloud-service-discovery&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-service-discovery&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud Service Discovery&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-form-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-form-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Form Handling&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-jdbc-template&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-jdbc-template&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring JDBC Template&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-mvc-exception-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc-exception-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC Exception Handling&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-orm&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-orm&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring ORM&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-security-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security Authentication&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-security-csrf-jwt&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-csrf-jwt&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security CSRF and JWT&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-spel&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-spel&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Expression Language&lt;/a&gt; — concept&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../test-driven-development&quot; class=&quot;internal alias&quot; data-slug=&quot;test-driven-development&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Test-Driven Development&lt;/a&gt; — concept&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;mechanisms--how-things-work&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Mechanisms &amp;#x26; How Things Work&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#mechanisms--how-things-work&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;em&gt;Auto-generated — edit to curate. Pages that explain processes/flows.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;comparisons--tradeoffs&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Comparisons &amp;#x26; Tradeoffs&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#comparisons--tradeoffs&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;em&gt;(No synthesis yet — create via ingest or query —save)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;suggested-reading-order&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Suggested Reading Order&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#suggested-reading-order&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;Browse Core Concepts above — start with most-linked page&lt;/li&gt;
&lt;li&gt;Follow Connections sections for dense graph traversal&lt;/li&gt;
&lt;/ol&gt;</content>
  </entry><entry>
    <title>api-gateway-pattern</title>
    <link href="https://animishraa05.github.io/wiki/java3/api-gateway-pattern" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/api-gateway-pattern.md" />
    <summary>The Problem In a microservices architecture, clients (web, mobile, third-party) would need to know about every service, handle authentication individually, and orchestrate multiple service calls for a single page.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="architecture" label="architecture" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In a microservices architecture, clients (web, mobile, third-party) would need to know about every service, handle authentication individually, and orchestrate multiple service calls for a single page. This creates tight coupling between clients and backend services, duplicates security logic, and forces clients to manage network complexity.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The API Gateway Pattern introduces a single entry point that routes client requests to the appropriate microservices. The gateway handles cross-cutting concerns — authentication, rate limiting, logging, request transformation — in one place. It can also aggregate responses from multiple services, reducing client-side complexity.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Single entry point&lt;/strong&gt;: All client requests go through the gateway, not directly to services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Route matching&lt;/strong&gt;: Gateway maps incoming request paths to target services — &lt;code class=&quot;notranslate&quot;&gt;GET /api/users/*&lt;/code&gt; → User Service&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication&lt;/strong&gt;: Gateway validates JWT tokens or API keys before forwarding requests — unauthenticated requests are rejected at the edge&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rate limiting&lt;/strong&gt;: Gateway tracks request rates per client and throttles excessive requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request/response transformation&lt;/strong&gt;: Gateway can modify headers, rewrite paths, transform request/response bodies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Aggregation&lt;/strong&gt;: A single client request might trigger multiple downstream calls — gateway aggregates responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backend for Frontend (BFF)&lt;/strong&gt;: Different gateways for different client types (web, mobile, IoT), each optimized for its client&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: api_gateway_pattern Pages: 1 --&gt;
&lt;svg width=&quot;393pt&quot; height=&quot;289pt&quot; viewBox=&quot;0.00 0.00 393.00 289.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 285.2)&quot;&gt;
&lt;title&gt;api_gateway_pattern&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-285.2 389.35,-285.2 389.35,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- WEB --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;WEB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;175.02,-281.2 109.66,-281.2 109.66,-245.2 175.02,-245.2 175.02,-281.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.34&quot; y=&quot;-259.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Web App&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GW&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;294.71,-208.2 167.97,-208.2 167.97,-157 294.71,-157 294.71,-208.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.34&quot; y=&quot;-193.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;API Gateway&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.34&quot; y=&quot;-179&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(auth, rate-limit,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.34&quot; y=&quot;-164.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;routing, aggregation)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- WEB&amp;#45;&amp;gt;GW --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;WEB-&gt;GW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M162.09,-244.76C171.72,-236.25 183.62,-225.74 194.82,-215.85&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;196.89,-218.69 202.07,-209.45 192.26,-213.45 196.89,-218.69&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MOBILE --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MOBILE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;269.36,-281.2 193.32,-281.2 193.32,-245.2 269.36,-245.2 269.36,-281.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;231.34&quot; y=&quot;-259.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Mobile App&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MOBILE&amp;#45;&amp;gt;GW --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MOBILE-&gt;GW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M231.34,-244.76C231.34,-237.42 231.34,-228.59 231.34,-219.95&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;234.84,-219.96 231.34,-209.96 227.84,-219.96 234.84,-219.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- THIRD --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIRD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;385.35,-281.2 287.33,-281.2 287.33,-245.2 385.35,-245.2 385.35,-281.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;336.34&quot; y=&quot;-259.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Third-Party API&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIRD&amp;#45;&amp;gt;GW --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIRD-&gt;GW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M313.04,-244.76C301.45,-236.08 287.09,-225.33 273.65,-215.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;275.85,-212.55 265.75,-209.36 271.66,-218.15 275.85,-212.55&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- S1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;S1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;84.68,-120 0,-120 0,-84 84.68,-84 84.68,-120&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;42.34&quot; y=&quot;-98.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;S1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;S1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M171.02,-156.51C146.48,-146.31 118.38,-134.62 94.71,-124.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;96.15,-121.59 85.57,-120.98 93.46,-128.05 96.15,-121.59&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- S2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;S2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;192.35,-120 102.33,-120 102.33,-84 192.35,-84 192.35,-120&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;147.34&quot; y=&quot;-98.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;S2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;S2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.76,-156.73C195.02,-147.62 184,-137.3 174.23,-128.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;176.83,-125.8 167.14,-121.53 172.05,-130.91 176.83,-125.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- S3 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;S3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;310.69,-120 209.99,-120 209.99,-84 310.69,-84 310.69,-120&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.34&quot; y=&quot;-98.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Product Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;S3 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;S3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M240.52,-156.73C243.56,-148.47 246.97,-139.23 250.1,-130.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;253.28,-132.26 253.45,-121.67 246.71,-129.84 253.28,-132.26&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- S4 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;S4&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;296.69,-36 189.99,-36 189.99,0 296.69,0 296.69,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;243.34&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Payment Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;S4 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;S4&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M284.12,-156.58C298.12,-147.19 311.5,-135.05 319.34,-120 326.73,-105.81 326.04,-98.53 319.34,-84 311.72,-67.44 297.56,-53.53 283.51,-42.88&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;285.78,-40.2 275.6,-37.24 281.71,-45.9 285.78,-40.2&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- S2&amp;#45;&amp;gt;S4 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;S2-&gt;S4&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M167.7,-83.61C181.32,-71.98 199.44,-56.5 214.53,-43.61&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;216.53,-46.5 221.86,-37.35 211.98,-41.18 216.53,-46.5&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;226.38&quot; y=&quot;-57&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;internal call&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Single entry point&lt;/strong&gt;: All external requests go through the gateway — simplifies client code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication at edge&lt;/strong&gt;: Validate tokens/API keys once at gateway, not per service&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rate limiting&lt;/strong&gt;: Per-client rate limits prevent abuse and ensure fair usage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request aggregation&lt;/strong&gt;: Combine multiple service responses into one client response&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Protocol translation&lt;/strong&gt;: Gateway can translate between protocols (HTTP to gRPC, WebSocket polling)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Backend for Frontend (BFF)&lt;/strong&gt;: Separate gateways optimized for specific client types&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load shedding&lt;/strong&gt;: Gateway can reject requests under load to protect downstream services&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-api-gateway&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-api-gateway&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud API Gateway&lt;/a&gt; — Spring Cloud’s implementation of the API Gateway pattern&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — API Gateway is a fundamental component of microservice architecture&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-service-discovery&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-service-discovery&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud Service Discovery&lt;/a&gt; — Gateway uses service discovery to route to instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../api-gateway-pattern&quot; class=&quot;internal alias&quot; data-slug=&quot;api-gateway-pattern&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;API Gateway Pattern&lt;/a&gt; — The general architectural pattern (self-reference)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-object&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-object&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Object&lt;/a&gt; — EJB Object is a client-side proxy; API Gateway is a server-side entry point&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Gateway SPOF&lt;/strong&gt;: If the gateway goes down, all requests fail — deploy multiple gateway instances behind a load balancer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latency addition&lt;/strong&gt;: Every request passes through the gateway, adding network hops — keep gateway logic lightweight&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gateway bloat&lt;/strong&gt;: Avoid putting business logic in the gateway — it should only handle cross-cutting concerns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BFF vs single gateway&lt;/strong&gt;: Single gateway works for simple architectures; BFF scales better with diverse client requirements&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WebSocket and gRPC&lt;/strong&gt;: Gateway must support non-HTTP protocols if services use WebSocket or gRPC&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>dispatcher-servlet</title>
    <link href="https://animishraa05.github.io/wiki/java3/dispatcher-servlet" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/dispatcher-servlet.md" />
    <summary>The Problem Without a central request-handling mechanism, every web page in an application manages its own request processing independently.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Without a central request-handling mechanism, every web page in an application manages its own request processing independently. This leads to duplicated infrastructure code (parameter parsing, security checks, view selection) scattered across pages, making the application hard to maintain and evolve.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;DispatcherServlet is Spring MVC’s front controller — a single servlet that receives all HTTP requests and delegates to specialized components for each step of request processing. It acts as the central entry point, coordinating handler mapping, controller execution, exception handling, and view resolution.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Request received&lt;/strong&gt;: All HTTP requests are mapped to DispatcherServlet in web.xml&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HandlerMapping lookup&lt;/strong&gt;: DispatcherServlet asks HandlerMapping to find the controller method matching the URL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HandlerAdapter&lt;/strong&gt;: Adapter invokes the controller method, adapting to different controller types&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controller executes&lt;/strong&gt;: Method processes the request, returns ModelAndView (or @ResponseBody)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception resolution&lt;/strong&gt;: HandlerExceptionResolver catches controller exceptions and maps them to error views&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;View resolution&lt;/strong&gt;: ViewResolver converts logical view name to actual view implementation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;View rendering&lt;/strong&gt;: View renders the model and sends the HTTP response&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: dispatcher_servlet Pages: 1 --&gt;
&lt;svg width=&quot;636pt&quot; height=&quot;359pt&quot; viewBox=&quot;0.00 0.00 636.00 359.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 354.8)&quot;&gt;
&lt;title&gt;dispatcher_servlet&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-354.8 632.38,-354.8 632.38,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- REQ --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REQ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;314.71,-350.8 219.35,-350.8 219.35,-314.8 314.71,-314.8 314.71,-350.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.03&quot; y=&quot;-329.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Request&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DS&lt;/title&gt;
&lt;polygon fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; points=&quot;326.33,-277.8 207.73,-277.8 207.73,-241.8 326.33,-241.8 326.33,-277.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.03&quot; y=&quot;-255.9&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;DispatcherServlet&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REQ&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REQ-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M267.03,-314.61C267.03,-307.03 267.03,-297.9 267.03,-289.34&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;270.53,-289.34 267.03,-279.34 263.53,-289.34 270.53,-289.34&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- HM --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;104.05,-193.8 0,-193.8 0,-157.8 104.05,-157.8 104.05,-193.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;52.03&quot; y=&quot;-172.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HandlerMapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;HM --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;HM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M208.83,-241.32C194.2,-236.26 178.7,-230.33 164.77,-223.8 155.47,-219.45 154.26,-216.29 145.03,-211.8 135.14,-206.99 124.41,-202.4 113.87,-198.22&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;115.43,-195.08 104.84,-194.74 112.91,-201.61 115.43,-195.08&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;190.9&quot; y=&quot;-214.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;find handler&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HA --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HA&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;235.05,-193.8 135,-193.8 135,-157.8 235.05,-157.8 235.05,-193.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;185.03&quot; y=&quot;-172.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HandlerAdapter&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;HA --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;HA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M249.64,-241.41C238.22,-229.99 223.1,-214.88 210.36,-202.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;213.01,-199.83 203.46,-195.24 208.06,-204.78 213.01,-199.83&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EXC --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EXC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;411.06,-193.8 252.99,-193.8 252.99,-157.8 411.06,-157.8 411.06,-193.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;332.03&quot; y=&quot;-172.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HandlerExceptionResolver&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;EXC --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;EXC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M326.69,-247.88C339.37,-242.69 351.27,-235.06 359.03,-223.8 363.51,-217.3 362.15,-210.02 358.31,-203.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;361.41,-201.47 352.72,-195.41 355.73,-205.57 361.41,-201.47&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;387.13&quot; y=&quot;-214.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;if exception&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VR --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;VR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;620.71,-193.8 531.35,-193.8 531.35,-157.8 620.71,-157.8 620.71,-193.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;576.03&quot; y=&quot;-172.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ViewResolver&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;VR --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;VR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M326.78,-251.33C365.52,-245.67 416.83,-236.66 461.03,-223.8 483.78,-217.18 508.18,-207.59 528.62,-198.79&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;529.78,-202.1 537.54,-194.89 526.97,-195.69 529.78,-202.1&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;520.85&quot; y=&quot;-214.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;resolve view&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HM&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HM-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M38.6,-194.02C32.78,-203.68 28.77,-215.43 35.96,-223.8 56.34,-247.5 135.89,-255.35 196,-257.84&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;195.72,-261.34 205.84,-258.21 195.98,-254.34 195.72,-261.34&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;88.5&quot; y=&quot;-214.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;HandlerExecutionChain&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;455.16,-109.8 284.9,-109.8 284.9,-73 455.16,-73 455.16,-109.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;370.03&quot; y=&quot;-95&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Controller&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;370.03&quot; y=&quot;-80.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(@RequestMapping method)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HA&amp;#45;&amp;gt;CTRL --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HA-&gt;CTRL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M224.26,-157.33C252.06,-144.94 289.6,-128.22 319.62,-114.85&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;320.8,-118.16 328.51,-110.89 317.95,-111.76 320.8,-118.16&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;303.06&quot; y=&quot;-130.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;invoke&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M388.83,-110.17C400.28,-122.34 413.84,-139.52 420.03,-157.8 429.45,-185.64 435.76,-202.03 416.03,-223.8 405.13,-235.83 370.69,-244.35 337.66,-249.97&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;337.36,-246.47 328.05,-251.52 338.48,-253.38 337.36,-246.47&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;462.33&quot; y=&quot;-172.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;ModelAndView&lt;/text&gt;
&lt;/g&gt;
&lt;!-- EXC&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EXC-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M282.41,-194.14C275.25,-198.77 268.83,-204.57 264.43,-211.8 261.09,-217.3 260.05,-223.86 260.21,-230.31&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;256.71,-230.54 261.38,-240.05 263.66,-229.71 256.71,-230.54&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;309.73&quot; y=&quot;-214.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;error ModelAndView&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VIEW --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;VIEW&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;603.03,-109.4 549.03,-109.4 549.03,-73.4 603.03,-73.4 603.03,-109.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;576.03&quot; y=&quot;-87.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;View&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VR&amp;#45;&amp;gt;VIEW --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;VR-&gt;VIEW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M576.03,-157.33C576.03,-146.84 576.03,-133.24 576.03,-121.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;579.53,-121.36 576.03,-111.36 572.53,-121.36 579.53,-121.36&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;628.38,-36 523.68,-36 523.68,0 628.38,0 628.38,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;576.03&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Response&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VIEW&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;VIEW-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M576.03,-73.12C576.03,-65.46 576.03,-56.24 576.03,-47.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;579.53,-47.89 576.03,-37.89 572.53,-47.89 579.53,-47.89&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Front controller&lt;/strong&gt;: Single entry point for all web requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pluggable components&lt;/strong&gt;: HandlerMapping, HandlerAdapter, ViewResolver, ExceptionResolver all configurable&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default behavior&lt;/strong&gt;: Spring Boot auto-configures sensible defaults for all components&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Servlet API independence&lt;/strong&gt;: Controllers don’t directly depend on HttpServletRequest/Response&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration&lt;/strong&gt;: Works with Spring Security’s filter chain seamlessly&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — DispatcherServlet is the core of Spring MVC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — DispatcherServlet is a Spring-managed bean wired via IoC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — Controllers are the handlers that DispatcherServlet invokes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc-exception-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc-exception-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC Exception Handling&lt;/a&gt; — HandlerExceptionResolver integrates with DispatcherServlet&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-object&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-object&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Object&lt;/a&gt; — EJB Object is a proxy; DispatcherServlet is a front controller&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Multiple DispatcherServlets&lt;/strong&gt;: Possible but rare — each defines its own application context, can’t share beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static resources&lt;/strong&gt;: DispatcherServlet must be configured to pass through static resources (CSS, JS) — use &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;mvc:resources&gt;&lt;/code&gt; or default servlet handler&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;404 without mapping&lt;/strong&gt;: No HandlerMapping match results in 404 — check servlet mapping URL patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Application context hierarchy&lt;/strong&gt;: DispatcherServlet creates its own WebApplicationContext (child of root context); only sees beans in its own context&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>distributed-tracing</title>
    <link href="https://animishraa05.github.io/wiki/java3/distributed-tracing" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/distributed-tracing.md" />
    <summary>The Problem In a monolithic application, debugging a request is straightforward — one log file, one thread.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="ops" label="ops" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In a monolithic application, debugging a request is straightforward — one log file, one thread. In microservices, a single user request spans multiple services, each with its own logs, on different machines. When something fails, finding the root cause requires manually correlating log entries across services — a tedious, near-impossible task.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Distributed tracing tracks a single request across multiple services by propagating a unique trace ID through every service call. Each service records spans (units of work) with timing, status, and metadata. A tracing system (Zipkin, Jaeger) collects and visualizes these spans, showing the full request path, timing breakdown, and errors.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Trace ID generation&lt;/strong&gt;: When a request enters the system (at the API Gateway), a unique trace ID is generated&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Propagation&lt;/strong&gt;: The trace ID and span ID are propagated via HTTP headers (&lt;code class=&quot;notranslate&quot;&gt;X-B3-TraceId&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;X-B3-SpanId&lt;/code&gt;) to downstream services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Span recording&lt;/strong&gt;: Each service creates spans for the work it does — e.g., controller method, database query, HTTP call&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Annotation&lt;/strong&gt;: Spans include annotations for key events (client send, server receive, error)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collection&lt;/strong&gt;: Services send completed spans to a collector (Zipkin server) asynchronously&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Visualization&lt;/strong&gt;: The Zipkin UI shows a waterfall diagram: one row per span, with timing and parent-child relationships&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: distributed_tracing Pages: 1 --&gt;
&lt;svg width=&quot;871pt&quot; height=&quot;149pt&quot; viewBox=&quot;0.00 0.00 871.00 149.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 145.4)&quot;&gt;
&lt;title&gt;distributed_tracing&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-145.4 866.98,-145.4 866.98,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- GATEWAY --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GATEWAY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;88.71,-51.2 0,-51.2 0,0 88.71,0 88.71,-51.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.36&quot; y=&quot;-36.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;API Gateway&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.36&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;trace: abc123&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;44.36&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;span: 1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;USR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;311,-103.4 222.29,-103.4 222.29,-37.8 311,-37.8 311,-103.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;266.65&quot; y=&quot;-88.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;266.65&quot; y=&quot;-74.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;trace: abc123&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;266.65&quot; y=&quot;-59.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;span: 2&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;266.65&quot; y=&quot;-45.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;parent: 1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY&amp;#45;&amp;gt;USR --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GATEWAY-&gt;USR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M89.14,-34.54C124.05,-41.68 173.14,-51.7 210.69,-59.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;209.96,-62.8 220.46,-61.37 211.36,-55.94 209.96,-62.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;155.5&quot; y=&quot;-60.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;header: trace=abc123&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ZIPKIN --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ZIPKIN&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;665.95,-65 571.6,-65 571.6,-28.2 665.95,-28.2 665.95,-65&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.77&quot; y=&quot;-50.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Zipkin Server&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.77&quot; y=&quot;-35.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(collector + UI)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY&amp;#45;&amp;gt;ZIPKIN --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GATEWAY-&gt;ZIPKIN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M89.09,-25.46C141.75,-25.44 232.87,-25.87 311,-28.6 397.78,-31.63 498.22,-38.09 559.87,-42.38&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;559.56,-45.87 569.78,-43.08 560.05,-38.89 559.56,-45.87&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;377.79&quot; y=&quot;-36.96&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;report spans&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ORD --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ORD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;534.6,-141.4 444.58,-141.4 444.58,-75.8 534.6,-75.8 534.6,-141.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;489.59&quot; y=&quot;-126.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;489.59&quot; y=&quot;-112.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;trace: abc123&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;489.59&quot; y=&quot;-97.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;span: 3&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;489.59&quot; y=&quot;-83.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;parent: 2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR&amp;#45;&amp;gt;ORD --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USR-&gt;ORD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M311.3,-78.11C346.17,-84.11 395.28,-92.55 432.97,-99.03&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;432.33,-102.48 442.78,-100.72 433.52,-95.58 432.33,-102.48&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;377.79&quot; y=&quot;-100.37&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;header: trace=abc123&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR&amp;#45;&amp;gt;ZIPKIN --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USR-&gt;ZIPKIN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M311.28,-67.61C374.14,-63.3 490.28,-55.34 560.14,-50.55&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;560.11,-54.06 569.85,-49.89 559.63,-47.08 560.11,-54.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;652.46,-134.2 585.09,-134.2 585.09,-83 652.46,-83 652.46,-134.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.77&quot; y=&quot;-119.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.77&quot; y=&quot;-105&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;span: 4&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;618.77&quot; y=&quot;-90.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;parent: 3&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M535.07,-108.6C547.45,-108.6 560.89,-108.6 573.27,-108.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;573.23,-112.1 583.23,-108.6 573.23,-105.1 573.23,-112.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;ZIPKIN --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;ZIPKIN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M535.07,-86.92C546.04,-81.57 557.84,-75.81 569.01,-70.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;570.21,-73.68 577.67,-66.15 567.15,-67.39 570.21,-73.68&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- WATERFALL --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;WATERFALL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;862.98,-86.6 702.95,-86.6 702.95,-6.6 862.98,-6.6 862.98,-86.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;782.97&quot; y=&quot;-71.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Waterfall View&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;782.97&quot; y=&quot;-57.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Gateway         ████&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;782.97&quot; y=&quot;-43&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User Service      ████&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;782.97&quot; y=&quot;-28.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order Service         ████&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;782.97&quot; y=&quot;-14.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DB                         ██&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ZIPKIN&amp;#45;&amp;gt;WATERFALL --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ZIPKIN-&gt;WATERFALL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M666.25,-46.6C674.19,-46.6 682.68,-46.6 691.31,-46.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;691.2,-50.1 701.2,-46.6 691.2,-43.1 691.2,-50.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Trace ID&lt;/strong&gt;: Unique identifier for an entire request across all services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Span&lt;/strong&gt;: A named, timed unit of work within a service (e.g., “SELECT from orders”)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parent span&lt;/strong&gt;: Spans form a tree — parent-child relationships show the call hierarchy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Propagation&lt;/strong&gt;: Trace context passed via HTTP headers (B3 format: X-B3-TraceId, X-B3-SpanId, X-B3-ParentSpanId)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sampling&lt;/strong&gt;: Not every request is traced — sampling rate configurable (e.g., trace 10% of requests)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Visualization&lt;/strong&gt;: Zipkin Jaeger, or Grafana Tempo show trace timelines as waterfall diagrams&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — Distributed tracing is essential when requests span multiple services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — Spring Cloud Sleuth (deprecated) / Micrometer Tracing provides auto-configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../url-to-rendering-flow&quot; class=&quot;internal alias&quot; data-slug=&quot;url-to-rendering-flow&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;URL to Rendering — Full Flow Analysis&lt;/a&gt; — Both trace end-to-end request flows&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../jta-jts&quot; class=&quot;internal alias&quot; data-slug=&quot;jta-jts&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JTA and JTS&lt;/a&gt; — JTA propagates transaction context; tracing propagates trace context&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Performance overhead&lt;/strong&gt;: Generating and reporting spans adds overhead — use sampling, especially at high throughput&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Async boundaries&lt;/strong&gt;: Trace context doesn’t propagate automatically across async boundaries — use &lt;code class=&quot;notranslate&quot;&gt;@Async&lt;/code&gt; + trace context propagation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sensitive data&lt;/strong&gt;: Spans may inadvertently capture sensitive data (SQL queries, request bodies) — sanitize span tags&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Clock skew&lt;/strong&gt;: Services on different machines have slightly different clocks — Zipkin adjusts using client/server send/receive timestamps&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;End-to-end setup&lt;/strong&gt;: Requires all services to participate — one service without tracing breaks the trace chain&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hibernate-annotations</title>
    <link href="https://animishraa05.github.io/wiki/java3/hibernate-annotations" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/hibernate-annotations.md" />
    <summary>The Problem Early Hibernate used XML mapping files (.hbm.xml) to define how Java classes mapped to database tables.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Early Hibernate used XML mapping files (.hbm.xml) to define how Java classes mapped to database tables. These files were verbose, hard to maintain, and separated the mapping definition from the code it described, making refactoring error-prone.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hibernate annotations allow developers to specify entity mappings directly in Java code using JPA-standard annotations. The most common annotations replace XML configuration with in-code metadata: &lt;code class=&quot;notranslate&quot;&gt;@Entity&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Table&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Id&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Column&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@GeneratedValue&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;&lt;code class=&quot;notranslate&quot;&gt;@Entity&lt;/code&gt;&lt;/strong&gt;: Marks a POJO class as a Hibernate entity mapped to a database table&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code class=&quot;notranslate&quot;&gt;@Table(name)&lt;/code&gt;&lt;/strong&gt;: Specifies the database table name (optional; defaults to class name)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code class=&quot;notranslate&quot;&gt;@Id&lt;/code&gt;&lt;/strong&gt;: Marks the primary key field&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;`@GeneratedValue(strategy)&lt;/strong&gt;: Specifies primary key generation: AUTO, IDENTITY, SEQUENCE, TABLE&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;`@Column(name, nullable, length)&lt;/strong&gt;: Maps a field to a column with optional constraints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code class=&quot;notranslate&quot;&gt;@Transient&lt;/code&gt;&lt;/strong&gt;: Marks a field that should NOT be persisted&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;`@Temporal(TemporalType.DATE)&lt;/strong&gt;: Specifies date/time precision for java.util.Date fields&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;`@Enumerated(EnumType.STRING)&lt;/strong&gt;: Specifies enum storage as STRING (name) or ORDINAL (index)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: hibernate_annotations Pages: 1 --&gt;
&lt;svg width=&quot;631pt&quot; height=&quot;260pt&quot; viewBox=&quot;0.00 0.00 631.00 260.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 256)&quot;&gt;
&lt;title&gt;hibernate_annotations&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-256 626.5,-256 626.5,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- POJO --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;POJO&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;104.71,-144.4 0,-144.4 0,-107.6 104.71,-107.6 104.71,-144.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;52.35&quot; y=&quot;-129.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Plain Java Class&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;52.35&quot; y=&quot;-115.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Entity)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ANNO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;221.09,-144 141.71,-144 141.71,-108 221.09,-108 221.09,-144&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;181.4&quot; y=&quot;-122.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Annotations&lt;/text&gt;
&lt;/g&gt;
&lt;!-- POJO&amp;#45;&amp;gt;ANNO --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;POJO-&gt;ANNO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.03,-126C113.24,-126 121.74,-126 129.93,-126&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;129.73,-129.5 139.73,-126 129.73,-122.5 129.73,-129.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ENTITY --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ENTITY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;344.97,-252 286.78,-252 286.78,-216 344.97,-216 344.97,-252&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.88&quot; y=&quot;-230.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Entity&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO&amp;#45;&amp;gt;ENTITY --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ANNO-&gt;ENTITY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M196.12,-144.29C210.17,-162.06 233.39,-188.93 258.09,-207 263.75,-211.15 270.16,-214.91 276.57,-218.23&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;274.66,-221.19 285.19,-222.4 277.71,-214.89 274.66,-221.19&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TABLE_A --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TABLE_A&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;363.98,-198 267.77,-198 267.77,-162 363.98,-162 363.98,-198&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.88&quot; y=&quot;-176.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Table(name)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO&amp;#45;&amp;gt;TABLE_A --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ANNO-&gt;TABLE_A&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M221.43,-141.91C233.23,-146.72 246.44,-152.1 259.11,-157.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;257.61,-160.44 268.19,-160.97 260.26,-153.96 257.61,-160.44&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ID --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ID&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;342.88,-144 288.88,-144 288.88,-108 342.88,-108 342.88,-144&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.88&quot; y=&quot;-122.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Id&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO&amp;#45;&amp;gt;ID --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ANNO-&gt;ID&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M221.43,-126C239.04,-126 259.76,-126 277.2,-126&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;277.17,-129.5 287.17,-126 277.17,-122.5 277.17,-129.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- GEN --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GEN&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;373.67,-90 258.09,-90 258.09,-54 373.67,-54 373.67,-90&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.88&quot; y=&quot;-68.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@GeneratedValue&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO&amp;#45;&amp;gt;GEN --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ANNO-&gt;GEN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M221.43,-110.09C233.23,-105.28 246.44,-99.9 259.11,-94.73&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;260.26,-98.04 268.19,-91.03 257.61,-91.56 260.26,-98.04&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COL --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;369.65,-36 262.11,-36 262.11,0 369.65,0 369.65,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.88&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Column(name)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ANNO&amp;#45;&amp;gt;COL --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ANNO-&gt;COL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M196.12,-107.71C210.17,-89.94 233.39,-63.07 258.09,-45 259.41,-44.03 260.77,-43.09 262.16,-42.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;263.67,-45.34 270.41,-37.17 260.04,-39.35 263.67,-45.34&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TABLE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TABLE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;511.39,-198 410.67,-198 410.67,-162 511.39,-162 511.39,-198&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;461.03&quot; y=&quot;-176.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database Table&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROW1 --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ROW1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;622.5,-225 568.5,-225 568.5,-189 622.5,-189 622.5,-225&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;595.5&quot; y=&quot;-203.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ROW1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TABLE&amp;#45;&amp;gt;ROW1 --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TABLE-&gt;ROW1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M511.73,-190.13C526.76,-193.19 543,-196.5 557.08,-199.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;556.35,-202.8 566.85,-201.36 557.75,-195.94 556.35,-202.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;539.94&quot; y=&quot;-200.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;rows&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROW2 --&gt;
&lt;g id=&quot;node10&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ROW2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;622.5,-171 568.5,-171 568.5,-135 622.5,-135 622.5,-171&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;595.5&quot; y=&quot;-149.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ROW2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TABLE&amp;#45;&amp;gt;ROW2 --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TABLE-&gt;ROW2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M511.73,-169.87C526.76,-166.81 543,-163.5 557.08,-160.63&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;557.75,-164.06 566.85,-158.64 556.35,-157.2 557.75,-164.06&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;539.94&quot; y=&quot;-168.69&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;rows&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ENTITY&amp;#45;&amp;gt;TABLE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ENTITY-&gt;TABLE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M345.16,-223.33C361.04,-217.34 381.48,-209.63 400.7,-202.38&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;401.68,-205.75 409.8,-198.95 399.21,-199.2 401.68,-205.75&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TABLE_A&amp;#45;&amp;gt;TABLE --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TABLE_A-&gt;TABLE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M364.15,-180C375.26,-180 387.27,-180 398.89,-180&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;398.84,-183.5 408.84,-180 398.84,-176.5 398.84,-183.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COL&amp;#45;&amp;gt;TABLE --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COL-&gt;TABLE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M361.8,-36.34C366.02,-38.94 370.06,-41.82 373.67,-45 407.68,-74.99 433.39,-121.52 447.58,-151.36&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;444.27,-152.56 451.64,-160.17 450.63,-149.62 444.27,-152.56&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;JPA-standard&lt;/strong&gt;: Annotations come from &lt;code class=&quot;notranslate&quot;&gt;javax.persistence.*&lt;/code&gt; (or &lt;code class=&quot;notranslate&quot;&gt;jakarta.persistence.*&lt;/code&gt;), not Hibernate-specific&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zero XML&lt;/strong&gt;: Full mapping can be done with annotations alone — no .hbm.xml files needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compile-time checked&lt;/strong&gt;: Wrong annotation usage is caught at compile time vs XML’s runtime failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default conventions&lt;/strong&gt;: Unspecified mappings default to sensible conventions (table = class name, column = field name)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid possible&lt;/strong&gt;: Annotations can override or supplement XML configurations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — Annotations are the modern way to configure Hibernate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../object-relational-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;object-relational-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Object-Relational Mapping&lt;/a&gt; — Annotations map Java objects to relational tables&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-entity-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-entity-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Entity Mapping&lt;/a&gt; — Relationship annotations (@OneToOne, @OneToMany, @ManyToMany)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-deployment-descriptor&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-deployment-descriptor&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Deployment Descriptor&lt;/a&gt; — XML-based vs annotation-based configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA entities use the same JPA annotations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Field vs property access&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Id&lt;/code&gt; placement determines access strategy — on field (FIELD access) or getter (PROPERTY access); mixing causes issues&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default column names&lt;/strong&gt;: Auto-generated column names follow naming strategy; explicit &lt;code class=&quot;notranslate&quot;&gt;@Column(name)&lt;/code&gt; avoids surprises&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GenerationType.IDENTITY&lt;/strong&gt;: Disables batch inserts because the DB must generate the ID before Hibernate knows it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Enumerated(ORDINAL)&lt;/strong&gt;: Default is ORDINAL (numeric), which breaks if enum ordering changes — prefer STRING&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hibernate-caching</title>
    <link href="https://animishraa05.github.io/wiki/java3/hibernate-caching" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/hibernate-caching.md" />
    <summary>The Problem Database access is expensive — each query requires network round trips, SQL parsing, and disk I/O.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Database access is expensive — each query requires network round trips, SQL parsing, and disk I/O. Applications often read the same data multiple times within a short period. Without caching, every read hits the database, wasting resources and increasing latency.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hibernate provides a multi-level caching architecture: the first-level cache (mandatory, session-scoped) stores entities loaded within a single session; the second-level cache (optional, session-factory-scoped) is shared across sessions; the query cache caches query results and their entity identifiers.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;First-level cache&lt;/strong&gt;: Every Hibernate Session has its own cache. When &lt;code class=&quot;notranslate&quot;&gt;session.get()&lt;/code&gt; loads an entity, Hibernate checks this cache first. If found, no database call. The cache is flushed (written to DB) at transaction commit or explicit &lt;code class=&quot;notranslate&quot;&gt;session.flush()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Second-level cache&lt;/strong&gt;: Pluggable cache (Ehcache, Redis, Infinispan) configured on the SessionFactory. When enabled for an entity, Hibernate checks L1 → L2 → database. L2 is shared across all sessions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query cache&lt;/strong&gt;: Caches query result identifiers (not entities). Requires second-level cache to be enabled. On re-execution, returns cached IDs and loads entities from L2 cache&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache concurrency strategies&lt;/strong&gt;: READ_ONLY (immutable data), READ_WRITE (frequent updates), NONSTRICT_READ_WRITE (rare updates), TRANSACTIONAL (full JTA support)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: hibernate_cache Pages: 1 --&gt;
&lt;svg width=&quot;344pt&quot; height=&quot;298pt&quot; viewBox=&quot;0.00 0.00 344.00 298.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 294.4)&quot;&gt;
&lt;title&gt;hibernate_cache&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-294.4 340.37,-294.4 340.37,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;163.37,-290.4 32.66,-290.4 32.66,-253.6 163.37,-253.6 163.37,-290.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;98.02&quot; y=&quot;-275.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;98.02&quot; y=&quot;-261.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;session.get(Entity, id)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;L1&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;110.03,-205.6 0,-205.6 0,-168.8 110.03,-168.8 110.03,-205.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;55.02&quot; y=&quot;-190.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;First-Level Cache&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;55.02&quot; y=&quot;-176.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(per Session)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;L1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;L1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M55.6,-253.23C48.86,-248.51 42.79,-242.69 38.77,-235.6 35.42,-229.69 35.63,-222.97 37.53,-216.48&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;40.72,-217.94 41.43,-207.37 34.28,-215.19 40.72,-217.94&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.4&quot; y=&quot;-226.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;1. check&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L1&amp;#45;&amp;gt;APP --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;L1-&gt;APP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M66.06,-206.01C69.38,-211.58 72.95,-217.78 76.02,-223.6 79.27,-229.77 82.55,-236.51 85.55,-242.92&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;82.3,-244.23 89.65,-251.86 88.66,-241.31 82.3,-244.23&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;111.57&quot; y=&quot;-226.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;found? return&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;L2&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;232.72,-120.8 105.31,-120.8 105.31,-84 232.72,-84 232.72,-120.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;169.02&quot; y=&quot;-106&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Second-Level Cache&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;169.02&quot; y=&quot;-91.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(per SessionFactory)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L1&amp;#45;&amp;gt;L2 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;L1-&gt;L2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M58.22,-168.44C60.83,-158.58 65.45,-146.73 73.51,-138.8 79.72,-132.7 87.07,-127.64 94.89,-123.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;96.15,-126.71 103.65,-119.22 93.12,-120.41 96.15,-126.71&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;115.76&quot; y=&quot;-141.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;2. not found, check&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L2&amp;#45;&amp;gt;APP --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;L2-&gt;APP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M169.74,-121.09C170.03,-147.89 167.29,-199.46 145.02,-235.6 142.79,-239.2 140.06,-242.57 137.04,-245.68&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;134.77,-243.01 129.65,-252.29 139.44,-248.23 134.77,-243.01&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.48&quot; y=&quot;-184.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;found? return&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;132.7,-36 65.33,-36 65.33,0 132.7,0 132.7,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;99.02&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- L2&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;L2-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M163.2,-83.52C159.54,-74.09 154.16,-62.69 147.02,-54 144,-50.32 140.51,-46.84 136.81,-43.59&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;139.12,-40.95 129.14,-37.42 134.74,-46.41 139.12,-40.95&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.66&quot; y=&quot;-57&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;3. not found, query&lt;/text&gt;
&lt;/g&gt;
&lt;!-- QC --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;QC&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;336.37,-205.6 249.67,-205.6 249.67,-168.8 336.37,-168.8 336.37,-205.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;293.02&quot; y=&quot;-190.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Query Cache&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;293.02&quot; y=&quot;-176.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(result IDs)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- QC&amp;#45;&amp;gt;L2 --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;QC-&gt;L2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M266.41,-168.44C248.52,-156.49 224.7,-140.58 205.1,-127.49&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;207.09,-124.62 196.83,-121.97 203.2,-130.44 207.09,-124.62&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;279.57&quot; y=&quot;-141.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;result IDs→entities&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DB&amp;#45;&amp;gt;L1 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DB-&gt;L1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M80.58,-36.39C69.15,-48.5 55.51,-65.7 49.32,-84 41.23,-107.89 43.87,-136.71 47.82,-157.64&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;44.34,-158.13 49.84,-167.19 51.19,-156.68 44.34,-158.13&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;72.67&quot; y=&quot;-99.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;store in L1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DB&amp;#45;&amp;gt;L2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DB-&gt;L2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M93.41,-36.3C91.43,-45.75 90.86,-57.27 96.32,-66 98.87,-70.08 102.05,-73.71 105.63,-76.92&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;103.34,-79.58 113.43,-82.8 107.55,-73.99 103.34,-79.58&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;119.67&quot; y=&quot;-57&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;store in L2&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;L1 cache&lt;/strong&gt;: Mandatory, session-scoped, cannot be disabled. Entities are removed when session is closed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L2 cache&lt;/strong&gt;: Optional, session-factory-scoped. Requires a cache provider (Ehcache, Redis)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query cache&lt;/strong&gt;: Optional, caches query result identifiers, requires L2 cache&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache regions&lt;/strong&gt;: Named regions allow fine-grained TTL and eviction policies per entity or query&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrency&lt;/strong&gt;: Four strategies (READ_ONLY, READ_WRITE, NONSTRICT_READ_WRITE, TRANSACTIONAL) matching data mutation patterns&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — Caching is a built-in Hibernate feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-orm&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-orm&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring ORM&lt;/a&gt; — Spring manages Hibernate sessions and transaction boundaries around caching&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../instance-pooling&quot; class=&quot;internal alias&quot; data-slug=&quot;instance-pooling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Instance Pooling&lt;/a&gt; — Pooling caches bean instances; Hibernate caching caches database data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../passivation&quot; class=&quot;internal alias&quot; data-slug=&quot;passivation&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Passivation&lt;/a&gt; — Both are memory management strategies (passivation serializes, caching keeps in memory)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA inherits Hibernate’s caching when using Hibernate as JPA provider&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;L1 cache scope&lt;/strong&gt;: L1 cache only lives as long as the Session — in a stateless (stateless session) scenario, there is no L1 cache benefit&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L2 cache invalidation&lt;/strong&gt;: Stale data occurs if another process modifies the database directly; use cache region timeouts&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query cache invalidation&lt;/strong&gt;: Any insert/update/delete on a cached query’s table invalidates the entire query cache region&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cluster consistency&lt;/strong&gt;: Distributed L2 caches (Redis) need careful serialization and invalidation strategies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debugging overhead&lt;/strong&gt;: Cached results hide database-level changes during development; always clear both caches during testing&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hibernate-entity-mapping</title>
    <link href="https://animishraa05.github.io/wiki/java3/hibernate-entity-mapping" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/hibernate-entity-mapping.md" />
    <summary>The Problem Relational databases model relationships using foreign keys and join tables, while Java models relationships using object references and collections.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Relational databases model relationships using foreign keys and join tables, while Java models relationships using object references and collections. Translating between these paradigms — one-to-one, one-to-many, many-to-many — requires explicit mapping configuration so Hibernate knows how to persist object graphs.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hibernate entity mapping defines how Java class relationships correspond to database foreign key and join table structures. The three relationship types mirror SQL: &lt;code class=&quot;notranslate&quot;&gt;@OneToOne&lt;/code&gt; (FK on either side), &lt;code class=&quot;notranslate&quot;&gt;@OneToMany&lt;/code&gt;/&lt;code class=&quot;notranslate&quot;&gt;@ManyToOne&lt;/code&gt; (FK on the many side), and &lt;code class=&quot;notranslate&quot;&gt;@ManyToMany&lt;/code&gt; (join table).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;One-to-One (&lt;code class=&quot;notranslate&quot;&gt;@OneToOne&lt;/code&gt;)&lt;/strong&gt;: A single entity instance relates to at most one other instance. Implemented via a foreign key column with a unique constraint on one table, or via a shared primary key&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;One-to-Many (&lt;code class=&quot;notranslate&quot;&gt;@OneToMany&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@ManyToOne&lt;/code&gt;)&lt;/strong&gt;: One entity has many children. The child table holds the foreign key. The &lt;code class=&quot;notranslate&quot;&gt;@ManyToOne&lt;/code&gt; side is always the owning side&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Many-to-Many (&lt;code class=&quot;notranslate&quot;&gt;@ManyToMany&lt;/code&gt;)&lt;/strong&gt;: Each entity can relate to many of the other. Requires a join table with two foreign key columns. Both sides use &lt;code class=&quot;notranslate&quot;&gt;@JoinTable&lt;/code&gt; with &lt;code class=&quot;notranslate&quot;&gt;joinColumns&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;inverseJoinColumns&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unidirectional vs Bidirectional&lt;/strong&gt;: Unidirectional means only one side navigates to the other; bidirectional means both sides have references&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: hibernate_mapping Pages: 1 --&gt;
&lt;svg width=&quot;639pt&quot; height=&quot;238pt&quot; viewBox=&quot;0.00 0.00 639.00 238.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 234)&quot;&gt;
&lt;title&gt;hibernate_mapping&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-234 635,-234 635,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;g id=&quot;clust1&quot; class=&quot;cluster&quot;&gt;
&lt;title&gt;cluster_java&lt;/title&gt;
&lt;polygon fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; points=&quot;8,-130 8,-222 623,-222 623,-130 8,-130&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.5&quot; y=&quot;-205.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;Java Entities&lt;/text&gt;
&lt;/g&gt;
&lt;g id=&quot;clust2&quot; class=&quot;cluster&quot;&gt;
&lt;title&gt;cluster_db&lt;/title&gt;
&lt;polygon fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; points=&quot;36,-8 36,-100 615,-100 615,-8 36,-8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;325.5&quot; y=&quot;-83.4&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;Database Tables&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A_1 --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;A_1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;107.77,-189.2 16.23,-189.2 16.23,-138 107.77,-138 107.77,-189.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;62&quot; y=&quot;-174.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;62&quot; y=&quot;-160&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@OneToOne&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;62&quot; y=&quot;-145.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@JoinColumn&lt;/text&gt;
&lt;/g&gt;
&lt;!-- T_1 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;T_1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;188.35,-60 43.65,-60 43.65,-23.2 188.35,-23.2 188.35,-60&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;116&quot; y=&quot;-45.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;users (id)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;116&quot; y=&quot;-30.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;profile_id (FK, UNIQUE)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A_1&amp;#45;&amp;gt;T_1 --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;A_1-&gt;T_1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M73.19,-137.74C81.95,-118.27 94.13,-91.2 103.26,-70.9&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;106.45,-72.36 107.36,-61.8 100.06,-69.48 106.45,-72.36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;103.55&quot; y=&quot;-111&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;maps to&lt;/text&gt;
&lt;/g&gt;
&lt;!-- B_1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;B_1&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;180,-181.6 126,-181.6 126,-145.6 180,-145.6 180,-181.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;153&quot; y=&quot;-160&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Profile&lt;/text&gt;
&lt;/g&gt;
&lt;!-- B_1&amp;#45;&amp;gt;T_1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;B_1-&gt;T_1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M147.62,-145.15C141.65,-125.8 131.93,-94.28 124.85,-71.29&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;128.24,-70.43 121.95,-61.91 121.56,-72.5 128.24,-70.43&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;156.69&quot; y=&quot;-111&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;maps to&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A_N --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;A_N&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;292.11,-189.2 197.89,-189.2 197.89,-138 292.11,-138 292.11,-189.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245&quot; y=&quot;-174.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Department&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245&quot; y=&quot;-160&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@OneToMany&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;245&quot; y=&quot;-145.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;mappedBy&lt;/text&gt;
&lt;/g&gt;
&lt;!-- T_N --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;T_N&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;365.7,-60 206.3,-60 206.3,-23.2 365.7,-23.2 365.7,-60&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;286&quot; y=&quot;-45.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;departments (id)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;286&quot; y=&quot;-30.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;employees (id, dept_id FK)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A_N&amp;#45;&amp;gt;T_N --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;A_N-&gt;T_N&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M253.5,-137.74C260.11,-118.36 269.31,-91.45 276.23,-71.19&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;279.5,-72.45 279.42,-61.85 272.88,-70.18 279.5,-72.45&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- B_N --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;B_N&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;404.11,-189.2 309.89,-189.2 309.89,-138 404.11,-138 404.11,-189.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;357&quot; y=&quot;-174.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Employee&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;357&quot; y=&quot;-160&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ManyToOne&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;357&quot; y=&quot;-145.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@JoinColumn&lt;/text&gt;
&lt;/g&gt;
&lt;!-- B_N&amp;#45;&amp;gt;T_N --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;B_N-&gt;T_N&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M342.29,-137.74C330.61,-118 314.31,-90.44 302.25,-70.06&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;305.42,-68.55 297.31,-61.72 299.39,-72.11 305.42,-68.55&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- A_M --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;A_M&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;523.44,-189.2 422.56,-189.2 422.56,-138 523.44,-138 523.44,-189.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;473&quot; y=&quot;-174.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Student&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;473&quot; y=&quot;-160&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ManyToMany&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;473&quot; y=&quot;-145.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@JoinTable&lt;/text&gt;
&lt;/g&gt;
&lt;!-- T_M --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;T_M&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;606.73,-67.2 383.27,-67.2 383.27,-16 606.73,-16 606.73,-67.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;495&quot; y=&quot;-52.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;students (id)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;495&quot; y=&quot;-38&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;courses (id)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;495&quot; y=&quot;-23.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;student_course (student_id, course_id)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- A_M&amp;#45;&amp;gt;T_M --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;A_M-&gt;T_M&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M477.56,-137.74C480.69,-120.68 484.88,-97.78 488.38,-78.72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;491.81,-79.39 490.17,-68.92 484.93,-78.13 491.81,-79.39&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- B_M --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;B_M&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;614.68,-182 541.32,-182 541.32,-145.2 614.68,-145.2 614.68,-182&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;578&quot; y=&quot;-167.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Course&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;578&quot; y=&quot;-152.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;mappedBy&lt;/text&gt;
&lt;/g&gt;
&lt;!-- B_M&amp;#45;&amp;gt;T_M --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;B_M-&gt;T_M&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M565.75,-144.89C553.42,-127.06 534.07,-99.09 518.72,-76.9&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;521.64,-74.96 513.07,-68.72 515.88,-78.94 521.64,-74.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Owning side&lt;/strong&gt;: The side that owns the foreign key; only the owning side’s changes are tracked&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;mappedBy&lt;/strong&gt;: Placed on the inverse (non-owning) side to reference the owning side’s field name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cascade&lt;/strong&gt;: Propagates operations (PERSIST, MERGE, REMOVE) from parent to child&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fetch type&lt;/strong&gt;: LAZY (load on access) vs EAGER (load immediately with parent)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Join columns&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@JoinColumn&lt;/code&gt; specifies the FK column name; &lt;code class=&quot;notranslate&quot;&gt;@JoinTable&lt;/code&gt; specifies the join table for M:N&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inheritance mapping&lt;/strong&gt;: Single table, joined table, or table-per-class strategies for class hierarchies&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — Mapping is a core feature of Hibernate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../object-relational-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;object-relational-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Object-Relational Mapping&lt;/a&gt; — Mapping implements ORM principles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-annotations&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-annotations&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Annotations&lt;/a&gt; — JPA annotations define mappings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../one-to-one-relationship&quot; class=&quot;internal alias&quot; data-slug=&quot;one-to-one-relationship&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;One-to-One Relationship (EJB)&lt;/a&gt; — EJB’s CMR vs Hibernate annotations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA repositories operate on mapped entities&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Bidirectional sync&lt;/strong&gt;: Always add convenience methods like &lt;code class=&quot;notranslate&quot;&gt;addEmployee(emp)&lt;/code&gt; to sync both sides of bidirectional associations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;equals/hashCode&lt;/strong&gt;: Never use the auto-generated ID in hashCode() before persisting — null ID causes inconsistent behavior in collections&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;EAGER fetch overuse&lt;/strong&gt;: Loading an entity with multiple EAGER collections creates a Cartesian product query&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Join table naming&lt;/strong&gt;: If &lt;code class=&quot;notranslate&quot;&gt;@JoinTable&lt;/code&gt; name is unspecified, Hibernate generates a default; explicit naming avoids surprises&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hibernate-orm-framework</title>
    <link href="https://animishraa05.github.io/wiki/java3/hibernate-orm-framework" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/hibernate-orm-framework.md" />
    <summary>The Problem Writing raw JDBC code for every database operation is repetitive, error-prone, and mixes SQL with Java logic.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Writing raw JDBC code for every database operation is repetitive, error-prone, and mixes SQL with Java logic. Object-relational impedance mismatch means Java objects (graphs, inheritance) don’t map naturally to relational tables (flat rows). Developers need a tool that automates this mapping and eliminates boilerplate.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Hibernate is an Object-Relational Mapping (ORM) framework for Java that maps Java classes to database tables and provides automatic SQL generation for CRUD operations. Developers work with Java objects; Hibernate translates those operations into SQL statements transparently.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Configuration&lt;/strong&gt;: A hibernate.cfg.xml file specifies database connection, dialect, and mapping classes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SessionFactory&lt;/strong&gt;: A thread-safe factory created once per application from the configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Session&lt;/strong&gt;: A lightweight, non-thread-safe wrapper around a JDBC connection, obtained per operation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transaction&lt;/strong&gt;: Wraps each unit of work. Hibernate uses its own Transaction API over JDBC transactions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Persistence operations&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;session.save(obj)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;session.get(Class, id)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;session.update(obj)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;session.delete(obj)&lt;/code&gt; — Hibernate generates and executes the SQL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automatic dirty checking&lt;/strong&gt;: Hibernate tracks entity state changes and flushes updates to the database automatically&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: hibernate_orm Pages: 1 --&gt;
&lt;svg width=&quot;123pt&quot; height=&quot;551pt&quot; viewBox=&quot;0.00 0.00 123.00 551.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 547.2)&quot;&gt;
&lt;title&gt;hibernate_orm&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-547.2 119.37,-547.2 119.37,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- App --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;App&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;109.38,-543.2 5.99,-543.2 5.99,-507.2 109.38,-507.2 109.38,-543.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-521.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Java Application&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HIB --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HIB&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;107.37,-471.2 8,-471.2 8,-435.2 107.37,-435.2 107.37,-471.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-449.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Hibernate ORM&lt;/text&gt;
&lt;/g&gt;
&lt;!-- App&amp;#45;&amp;gt;HIB --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;App-&gt;HIB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-506.9C57.68,-499.61 57.68,-490.93 57.68,-482.74&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-482.82 57.68,-472.82 54.18,-482.82 61.18,-482.82&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CFG --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CFG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;115.37,-399.2 0,-399.2 0,-362.4 115.37,-362.4 115.37,-399.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-384.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Configuration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-370&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(hibernate.cfg.xml)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HIB&amp;#45;&amp;gt;CFG --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HIB-&gt;CFG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-434.8C57.68,-427.58 57.68,-419 57.68,-410.87&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-411 57.68,-401 54.18,-411 61.18,-411&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SF --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SF&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;107.03,-326.4 8.33,-326.4 8.33,-289.6 107.03,-289.6 107.03,-326.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-311.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SessionFactory&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-297.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(1 per app)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;SF --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;SF&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-361.93C57.68,-354.67 57.68,-346.08 57.68,-337.97&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-338.13 57.68,-328.13 54.18,-338.13 61.18,-338.13&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SESS --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SESS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;105.04,-253.6 10.33,-253.6 10.33,-216.8 105.04,-216.8 105.04,-253.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-238.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Session&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-224.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(per operation)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SF&amp;#45;&amp;gt;SESS --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SF-&gt;SESS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-289.13C57.68,-281.87 57.68,-273.28 57.68,-265.17&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-265.33 57.68,-255.33 54.18,-265.33 61.18,-265.33&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TX --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;110.7,-180.8 4.67,-180.8 4.67,-144 110.7,-144 110.7,-180.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-166&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Transaction&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-151.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(per unit of work)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SESS&amp;#45;&amp;gt;TX --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SESS-&gt;TX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-216.33C57.68,-209.07 57.68,-200.48 57.68,-192.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-192.53 57.68,-182.53 54.18,-192.53 61.18,-192.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JDBC --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JDBC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;99.02,-108 16.35,-108 16.35,-72 99.02,-72 99.02,-108&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-86.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JDBC Driver&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TX&amp;#45;&amp;gt;JDBC --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TX-&gt;JDBC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-143.64C57.68,-136.3 57.68,-127.61 57.68,-119.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-119.54 57.68,-109.54 54.18,-119.54 61.18,-119.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;91.37,-36 24,-36 24,0 91.37,0 91.37,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;57.68&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JDBC&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JDBC-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M57.68,-71.7C57.68,-64.41 57.68,-55.73 57.68,-47.54&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;61.18,-47.62 57.68,-37.62 54.18,-47.62 61.18,-47.62&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;semantic-network&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Semantic Network&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#semantic-network&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: semantic_hibernate Pages: 1 --&gt;
&lt;svg width=&quot;265pt&quot; height=&quot;194pt&quot; viewBox=&quot;0.00 0.00 265.00 194.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 189.56)&quot;&gt;
&lt;title&gt;semantic_hibernate&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-189.56 260.97,-189.56 260.97,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- THIS --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THIS&lt;/title&gt;
&lt;ellipse fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; cx=&quot;133.85&quot; cy=&quot;-86.38&quot; rx=&quot;70.39&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;133.85&quot; y=&quot;-82.48&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Hibernate ORM&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JDBC --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JDBC&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;185.71&quot; cy=&quot;-23.83&quot; rx=&quot;27.67&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;185.71&quot; y=&quot;-20.53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;JDBC&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;JDBC --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--JDBC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M148.57,-68.62C156.12,-59.52 165.23,-48.53 172.54,-39.71&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.05&quot; y=&quot;-56.87&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ORM --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ORM&lt;/title&gt;
&lt;ellipse fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; cx=&quot;90.09&quot; cy=&quot;-18&quot; rx=&quot;90.09&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;90.09&quot; y=&quot;-14.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Object-Relational Mapping&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;ORM --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--ORM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M122.35,-68.41C115.97,-58.44 108.06,-46.07 101.66,-36.08&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;93.5&quot; y=&quot;-54.95&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;built from&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JPA --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JPA&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;55.51&quot; cy=&quot;-107.72&quot; rx=&quot;27&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;55.51&quot; y=&quot;-104.42&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;JPA&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;JPA --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--JPA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;5 2&quot; d=&quot;M85.13,-99.65C83.63,-100.06 82.16,-100.46 80.71,-100.86&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;103.18&quot; y=&quot;-102.95&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SPRING --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SPRING&lt;/title&gt;
&lt;ellipse fill=&quot;#d4edda&quot; stroke=&quot;black&quot; cx=&quot;209.64&quot; cy=&quot;-115.84&quot; rx=&quot;47.34&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;209.64&quot; y=&quot;-112.54&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;Spring ORM&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;SPRING --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--SPRING&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M173.07,-101.63C174.09,-102.02 175.1,-102.41 176.1,-102.8&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;154.32&quot; y=&quot;-104.91&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;builds into&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SQL --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SQL&lt;/title&gt;
&lt;ellipse fill=&quot;#f0f0f0&quot; stroke=&quot;black&quot; cx=&quot;130.02&quot; cy=&quot;-167.56&quot; rx=&quot;27&quot; ry=&quot;18&quot;&gt;&lt;/ellipse&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;130.02&quot; y=&quot;-164.26&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;11.00&quot;&gt;SQL&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THIS&amp;#45;&amp;#45;SQL --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THIS--SQL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M132.98,-104.8C132.35,-118.09 131.51,-135.95 130.88,-149.22&quot;&gt;&lt;/path&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;118.17&quot; y=&quot;-129.71&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;9.00&quot;&gt;related&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Automatic SQL&lt;/strong&gt;: Generates INSERT/UPDATE/DELETE/SELECT from object operations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transparent persistence&lt;/strong&gt;: Developer works with POJOs, not JDBC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Caching&lt;/strong&gt;: First-level (session-scoped) and second-level (session-factory-scoped) cache&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lazy loading&lt;/strong&gt;: Child entities loaded from database only when accessed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HQL&lt;/strong&gt;: Object-oriented query language using class names instead of table names&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dialects&lt;/strong&gt;: Database-specific SQL generation (MySQL, Oracle, PostgreSQL, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-jdbc&quot; class=&quot;internal alias&quot; data-slug=&quot;java-jdbc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JDBC&lt;/a&gt; — Hibernate uses JDBC under the hood for database connectivity&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../object-relational-mapping&quot; class=&quot;internal alias&quot; data-slug=&quot;object-relational-mapping&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Object-Relational Mapping&lt;/a&gt; — Hibernate implements ORM principles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-orm&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-orm&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring ORM&lt;/a&gt; — Spring integrates Hibernate via SessionFactory and transaction management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA builds on Hibernate as the default JPA provider&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../hql&quot; class=&quot;internal alias&quot; data-slug=&quot;hql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Query Language&lt;/a&gt; — HQL is Hibernate’s object-oriented query language&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../container-managed-persistence&quot; class=&quot;internal alias&quot; data-slug=&quot;container-managed-persistence&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Container-Managed Persistence&lt;/a&gt; — CMP is EJB’s ORM approach; Hibernate is standalone&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;N+1 query problem&lt;/strong&gt;: Lazy loading a collection in a loop triggers N additional queries; use JOIN FETCH&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open Session in View&lt;/strong&gt;: Keeping a session open during view rendering can cause LazyInitializationException&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;equals() and hashCode()&lt;/strong&gt;: Must implement correctly for entities in collections, but primary keys change before persist&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version field&lt;/strong&gt;: Optimistic locking requires a &lt;code class=&quot;notranslate&quot;&gt;@Version&lt;/code&gt; annotated field&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>hql</title>
    <link href="https://animishraa05.github.io/wiki/java3/hql" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/hql.md" />
    <summary>The Problem Standard SQL uses table and column names, making queries database-specific and tightly coupled to the physical schema.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Standard SQL uses table and column names, making queries database-specific and tightly coupled to the physical schema. When using ORM, developers want to query using Java class and field names instead, maintaining the object-oriented abstraction even during queries.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;HQL (Hibernate Query Language) is an object-oriented query language that operates on entity class names and their fields instead of table and column names. HQL queries are translated by Hibernate into native SQL for the configured database dialect. Hibernate also supports Native SQL queries for database-specific features.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;HQL syntax&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;from Employee e where e.department.name = :deptName&lt;/code&gt; — uses class and field names&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query creation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;session.createQuery(&quot;from Employee&quot;, Employee.class)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parameter binding&lt;/strong&gt;: Named parameters (&lt;code class=&quot;notranslate&quot;&gt;:paramName&lt;/code&gt;) or positional (&lt;code class=&quot;notranslate&quot;&gt;?1&lt;/code&gt;) prevent SQL injection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Translation&lt;/strong&gt;: Hibernate parses HQL, generates an AST, transforms it to SQL for the target dialect&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Result processing&lt;/strong&gt;: Returns &lt;code class=&quot;notranslate&quot;&gt;List&amp;#x3C;Entity&gt;&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;Stream&amp;#x3C;Entity&gt;&lt;/code&gt; automatically mapped to entities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Native SQL&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;session.createNativeQuery(&quot;SELECT * FROM emp&quot;, Employee.class)&lt;/code&gt; for raw SQL&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: hql_flow Pages: 1 --&gt;
&lt;svg width=&quot;939pt&quot; height=&quot;114pt&quot; viewBox=&quot;0.00 0.00 939.00 114.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 110)&quot;&gt;
&lt;title&gt;hql_flow&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-110 935.22,-110 935.22,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;90.02,-75 0,-75 0,-38.2 90.02,-38.2 90.02,-75&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;45.01&quot; y=&quot;-60.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;45.01&quot; y=&quot;-45.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;createQuery()&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HQL --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HQL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;231.37,-82.2 126.02,-82.2 126.02,-31 231.37,-31 231.37,-82.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.69&quot; y=&quot;-67.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HQL String&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.69&quot; y=&quot;-53&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;&#039;from Employee&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.69&quot; y=&quot;-38.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;e.name = :name&#039;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;HQL --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;HQL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M90.23,-56.6C97.94,-56.6 106.11,-56.6 114.23,-56.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;114.11,-60.1 124.11,-56.6 114.11,-53.1 114.11,-60.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PARSER --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PARSER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;377.4,-75 267.37,-75 267.37,-38.2 377.4,-38.2 377.4,-75&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;322.38&quot; y=&quot;-60.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HQL Parser&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;322.38&quot; y=&quot;-45.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(AST Generation)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HQL&amp;#45;&amp;gt;PARSER --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HQL-&gt;PARSER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M231.65,-56.6C239.49,-56.6 247.66,-56.6 255.74,-56.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;255.54,-60.1 265.54,-56.6 255.54,-53.1 255.54,-60.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TRANS --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TRANS&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;502.75,-75 413.4,-75 413.4,-38.2 502.75,-38.2 502.75,-75&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;458.08&quot; y=&quot;-60.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Translator&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;458.08&quot; y=&quot;-45.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(HQL → SQL)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PARSER&amp;#45;&amp;gt;TRANS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PARSER-&gt;TRANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M377.76,-56.6C385.63,-56.6 393.74,-56.6 401.63,-56.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;401.46,-60.1 411.46,-56.6 401.46,-53.1 401.46,-60.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DIALECT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DIALECT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;676.95,-106 544.93,-106 544.93,-69.2 676.95,-69.2 676.95,-106&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;610.94&quot; y=&quot;-91.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database Dialect&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;610.94&quot; y=&quot;-76.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(MySQL, Oracle, etc.)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TRANS&amp;#45;&amp;gt;DIALECT --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TRANS-&gt;DIALECT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M503.12,-65.65C512.64,-67.61 522.96,-69.73 533.32,-71.86&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;532.55,-75.27 543.05,-73.86 533.96,-68.41 532.55,-75.27&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SQL --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SQL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;683.13,-51.2 538.75,-51.2 538.75,0 683.13,0 683.13,-51.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;610.94&quot; y=&quot;-36.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Native SQL&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;610.94&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SELECT * FROM emp&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;610.94&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;WHERE emp_name = ?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TRANS&amp;#45;&amp;gt;SQL --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TRANS-&gt;SQL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M503.12,-47.55C510.71,-45.99 518.82,-44.32 527.05,-42.63&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;527.74,-46.06 536.83,-40.62 526.33,-39.21 527.74,-46.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;786.5,-43.6 719.13,-43.6 719.13,-7.6 786.5,-7.6 786.5,-43.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;752.82&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SQL&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SQL-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M683.52,-25.6C691.73,-25.6 699.92,-25.6 707.61,-25.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;707.36,-29.1 717.36,-25.6 707.36,-22.1 707.36,-29.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RES --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RES&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;931.22,-44 822.5,-44 822.5,-7.2 931.22,-7.2 931.22,-44&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;876.86&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;List&amp;#x3C;Employee&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;876.86&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(mapped entities)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DB&amp;#45;&amp;gt;RES --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DB-&gt;RES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M786.85,-25.6C794.32,-25.6 802.51,-25.6 810.8,-25.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;810.59,-29.1 820.59,-25.6 810.59,-22.1 810.59,-29.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Object-oriented&lt;/strong&gt;: Queries use Java class names (&lt;code class=&quot;notranslate&quot;&gt;Employee&lt;/code&gt;) and field names (&lt;code class=&quot;notranslate&quot;&gt;firstName&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dialect-independent&lt;/strong&gt;: Same HQL works on MySQL, Oracle, PostgreSQL — Hibernate handles translation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Named parameters&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;:name&lt;/code&gt; syntax with &lt;code class=&quot;notranslate&quot;&gt;setParameter(&quot;name&quot;, value)&lt;/code&gt; for safe parameter binding&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Aggregation&lt;/strong&gt;: Supports &lt;code class=&quot;notranslate&quot;&gt;SELECT&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;GROUP BY&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;HAVING&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;ORDER BY&lt;/code&gt;, aggregate functions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Joins&lt;/strong&gt;: Implicit path navigation (&lt;code class=&quot;notranslate&quot;&gt;emp.department.name&lt;/code&gt;) and explicit JOIN FETCH for loading associations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Native SQL fallback&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;createNativeQuery()&lt;/code&gt; for database-specific features, stored procedures, or complex queries&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — HQL is Hibernate’s query language&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../ejb-ql&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-ql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Query Language (EJB-QL)&lt;/a&gt; — HQL is the ORM successor to EJB-QL’s concept&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-jdbc&quot; class=&quot;internal alias&quot; data-slug=&quot;java-jdbc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JDBC&lt;/a&gt; — Native SQL in Hibernate still uses JDBC under the hood&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA’s @Query uses JPQL (similar to HQL)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-ql&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-ql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB-QL&lt;/a&gt; — EJB-QL is more limited, HQL supports richer expressions and native SQL&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;N+1 with joins&lt;/strong&gt;: Default fetching is LAZY; HQL queries without JOIN FETCH trigger N+1 queries for associations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HQL vs SQL mindset&lt;/strong&gt;: HQL operates on entities, not rows — &lt;code class=&quot;notranslate&quot;&gt;select e.firstName, e.lastName&lt;/code&gt; returns &lt;code class=&quot;notranslate&quot;&gt;Object[]&lt;/code&gt;, not entities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Positional parameters&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;?&lt;/code&gt; positional params are deprecated in Hibernate 5+ in favor of &lt;code class=&quot;notranslate&quot;&gt;:named&lt;/code&gt; parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalar queries&lt;/strong&gt;: Aggregate results need proper typing — &lt;code class=&quot;notranslate&quot;&gt;query.getSingleResult()&lt;/code&gt; returns &lt;code class=&quot;notranslate&quot;&gt;Long&lt;/code&gt; for COUNT, not &lt;code class=&quot;notranslate&quot;&gt;Integer&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>java-microservices</title>
    <link href="https://animishraa05.github.io/wiki/java3/java-microservices" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/java-microservices.md" />
    <summary>The Problem Monolithic applications grow too large to maintain — a single codebase with millions of lines, long build times, brittle deployments where one bug takes down the entire application.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="architecture" label="architecture" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Monolithic applications grow too large to maintain — a single codebase with millions of lines, long build times, brittle deployments where one bug takes down the entire application. Scaling requires scaling the whole app, not just the bottleneck component. Teams can’t work independently on different parts.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Java Microservices is an architectural style where a Java application is structured as a collection of small, independently deployable services, each owning its own database and communicating via lightweight protocols (HTTP/REST or messaging). Each service is developed, deployed, and scaled independently, typically using Spring Boot.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Service decomposition&lt;/strong&gt;: Each business capability becomes a separate service (User Service, Order Service, Payment Service)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Independent deployment&lt;/strong&gt;: Each service is its own Spring Boot JAR, deployed separately, with its own CI/CD pipeline&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inter-service communication&lt;/strong&gt;: Services communicate via REST APIs (synchronous) or message queues (asynchronous)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service discovery&lt;/strong&gt;: Eureka registry enables services to find each other by logical name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;API Gateway&lt;/strong&gt;: Single entry point routes requests to appropriate services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Database per service&lt;/strong&gt;: Each service owns its database — no shared database across services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distributed tracing&lt;/strong&gt;: Sleuth + Zipkin trace requests across service boundaries for debugging&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: microservices Pages: 1 --&gt;
&lt;svg width=&quot;571pt&quot; height=&quot;349pt&quot; viewBox=&quot;0.00 0.00 571.00 349.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 345.4)&quot;&gt;
&lt;title&gt;microservices&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-345.4 567.04,-345.4 567.04,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;237.04,-341.4 122.32,-341.4 122.32,-305.4 237.04,-305.4 237.04,-341.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.68&quot; y=&quot;-319.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client Applications&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GW&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;222.7,-268.4 136.67,-268.4 136.67,-232.4 222.7,-232.4 222.7,-268.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.68&quot; y=&quot;-246.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;API Gateway&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;GW --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;GW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.68,-305.21C179.68,-297.63 179.68,-288.5 179.68,-279.94&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;183.18,-279.94 179.68,-269.94 176.18,-279.94 183.18,-279.94&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- USR --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;USR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;170.02,-195.4 85.34,-195.4 85.34,-158.6 170.02,-158.6 170.02,-195.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;127.68&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;127.68&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Database)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;USR --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;USR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M167.09,-232.12C161.16,-223.97 153.94,-214.06 147.31,-204.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;150.3,-203.12 141.59,-197.09 144.65,-207.24 150.3,-203.12&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORD --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ORD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;309.69,-195.4 219.67,-195.4 219.67,-158.6 309.69,-158.6 309.69,-195.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;264.68&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;264.68&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Database)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GW&amp;#45;&amp;gt;ORD --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GW-&gt;ORD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M200.26,-232.12C210.57,-223.45 223.25,-212.8 234.63,-203.24&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;236.84,-205.96 242.25,-196.84 232.34,-200.6 236.84,-205.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EUREKA --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EUREKA&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;400.36,-36.8 297,-36.8 297,0 400.36,0 400.36,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.68&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Eureka&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.68&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service Registry&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USR-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M112.66,-158.2C95.97,-136.17 73.88,-98.54 94.34,-73.8 147.85,-9.07 198.36,-53.17 285.43,-36.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;285.98,-40.42 295.04,-34.92 284.53,-33.58 285.98,-40.42&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;111.01&quot; y=&quot;-89.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;register&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONFIG --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONFIG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;226.36,-110.2 137,-110.2 137,-74.2 226.36,-74.2 226.36,-110.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;181.68&quot; y=&quot;-88.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Config Server&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR&amp;#45;&amp;gt;CONFIG --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USR-&gt;CONFIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M138.59,-158.34C144.18,-149.39 151.14,-138.36 157.54,-128.6 159.44,-125.71 161.44,-122.7 163.45,-119.71&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;166.2,-121.89 168.92,-111.65 160.41,-117.96 166.2,-121.89&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;183.11&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;fetch config&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TRACE --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TRACE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;279.03,-36.8 154.33,-36.8 154.33,0 279.03,0 279.03,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;216.68&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Zipkin&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;216.68&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Distributed Tracing)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USR&amp;#45;&amp;gt;TRACE --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USR-&gt;TRACE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M84.88,-160.97C39.94,-142.83 -20.59,-110.19 7.55,-73.8 24.26,-52.19 89.64,-37.56 142.91,-28.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;143.24,-32.45 152.58,-27.45 142.16,-25.54 143.24,-32.45&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;35.62&quot; y=&quot;-89.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;report traces&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAY --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;389.03,-110.6 282.33,-110.6 282.33,-73.8 389.03,-73.8 389.03,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;335.68&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Payment Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;335.68&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Database)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;PAY --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;PAY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M279.74,-158.44C289.46,-147.1 302.29,-132.14 313.21,-119.41&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;315.56,-122.04 319.42,-112.17 310.25,-117.48 315.56,-122.04&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- NOT --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;NOT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;563.04,-110.6 444.33,-110.6 444.33,-73.8 563.04,-73.8 563.04,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;503.68&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Notification Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;503.68&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Message Queue)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;NOT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;NOT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M310.05,-170.88C344.19,-165.96 391.62,-156.79 430.68,-140.6 445,-134.66 459.57,-125.87 471.88,-117.47&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;473.84,-120.37 479.99,-111.75 469.8,-114.66 473.84,-120.37&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M310.13,-166.72C340.65,-157.87 378.64,-141.18 397.68,-110.6 411.03,-89.16 394.97,-63.79 377.76,-45.26&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;380.45,-43 370.94,-38.34 375.47,-47.92 380.45,-43&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;CONFIG --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;CONFIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M247.08,-158.44C235.45,-146.84 220.01,-131.44 207.06,-118.52&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;209.6,-116.1 200.05,-111.52 204.65,-121.06 209.6,-116.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ORD&amp;#45;&amp;gt;TRACE --&gt;
&lt;g id=&quot;edge12&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ORD-&gt;TRACE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M259.97,-158.18C254.48,-137.71 244.97,-103.17 235.68,-73.8 232.99,-65.28 229.86,-56.07 226.93,-47.7&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;230.26,-46.63 223.62,-38.38 223.66,-48.97 230.26,-46.63&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAY&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAY-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M338.9,-73.45C340.28,-65.8 341.94,-56.66 343.49,-48.08&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;346.9,-48.9 345.24,-38.43 340.01,-47.65 346.9,-48.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAY&amp;#45;&amp;gt;TRACE --&gt;
&lt;g id=&quot;edge13&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAY-&gt;TRACE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M306.27,-73.45C291.1,-64.3 272.41,-53.02 256.02,-43.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;257.84,-40.14 247.47,-37.97 254.22,-46.14 257.84,-40.14&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Independent deployability&lt;/strong&gt;: Each service has its own build, test, deploy pipeline&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Decentralized data&lt;/strong&gt;: Each service owns its database — no shared schema, no cross-service transactions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Technology heterogeneity&lt;/strong&gt;: Each service can use different technology stacks (though in Java, all typically Spring Boot)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resilience&lt;/strong&gt;: Failure in one service doesn’t cascade — circuit breakers, fallbacks, bulkheads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Scale only the services that need it (e.g., more Order Service instances during sales)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Team autonomy&lt;/strong&gt;: Teams own their services end-to-end — development, testing, deployment, operations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Each microservice is a Spring Boot application&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — Infrastructure (discovery, gateway, config, tracing) comes from Spring Cloud&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-rest-api&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-rest-api&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot REST API&lt;/a&gt; — Services communicate via REST APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../api-gateway-pattern&quot; class=&quot;internal alias&quot; data-slug=&quot;api-gateway-pattern&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;API Gateway Pattern&lt;/a&gt; — Gateway is the entry point for all microservice requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../service-discovery-registry&quot; class=&quot;internal alias&quot; data-slug=&quot;service-discovery-registry&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Service Discovery and Registry&lt;/a&gt; — Eureka enables service-to-service discovery&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../backend-architecture&quot; class=&quot;internal alias&quot; data-slug=&quot;backend-architecture&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Backend Architecture&lt;/a&gt; — Monolithic vs microservices architecture tradeoffs&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Distributed transactions&lt;/strong&gt;: No ACID across services — use Saga pattern (choreography or orchestration)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Network latency&lt;/strong&gt;: Inter-service calls add network overhead — use async messaging for non-critical paths&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data consistency&lt;/strong&gt;: Eventual consistency across services — handle stale data gracefully&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testing complexity&lt;/strong&gt;: End-to-end testing requires running all services — use contract testing (Pact)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operational overhead&lt;/strong&gt;: Monitoring, logging, deploying many services requires mature DevOps practices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Debugging&lt;/strong&gt;: A single user request spans multiple services — distributed tracing is essential&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>jpa-pagination-sorting</title>
    <link href="https://animishraa05.github.io/wiki/java3/jpa-pagination-sorting" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/jpa-pagination-sorting.md" />
    <summary>The Problem Returning all rows from a large database table in a single query consumes excessive memory, slows response times, and overwhelms clients.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Returning all rows from a large database table in a single query consumes excessive memory, slows response times, and overwhelms clients. Without a standard way to page and sort results, developers must manually write LIMIT/OFFSET SQL and handle page navigation, which is tedious and repetitive.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Data JPA provides &lt;code class=&quot;notranslate&quot;&gt;Pageable&lt;/code&gt; (pagination parameters) and &lt;code class=&quot;notranslate&quot;&gt;Sort&lt;/code&gt; (ordering parameters) as standard abstractions for querying subsets of data. Repository methods accept &lt;code class=&quot;notranslate&quot;&gt;Pageable&lt;/code&gt; to return &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;T&gt;&lt;/code&gt; objects containing the requested slice plus total count metadata. Sorting can be combined with pagination or used independently.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Pageable&lt;/strong&gt;: Interface with &lt;code class=&quot;notranslate&quot;&gt;pageNumber&lt;/code&gt; (0-indexed), &lt;code class=&quot;notranslate&quot;&gt;pageSize&lt;/code&gt;, and optional &lt;code class=&quot;notranslate&quot;&gt;Sort&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PageRequest&lt;/strong&gt;: Concrete implementation: &lt;code class=&quot;notranslate&quot;&gt;PageRequest.of(0, 20, Sort.by(&quot;lastName&quot;))&lt;/code&gt; — page 1, 20 items, sorted by lastName&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repository acceptance&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;User&gt; findAll(Pageable pageable)&lt;/code&gt; — Spring Data adds LIMIT, OFFSET, and COUNT query&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page&lt;t&gt; response&lt;/t&gt;&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;getContent()&lt;/code&gt; (list of entities), &lt;code class=&quot;notranslate&quot;&gt;getTotalElements()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;getTotalPages()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;getNumber()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;hasNext()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Sort.by(&quot;lastName&quot;).descending().and(Sort.by(&quot;firstName&quot;))&lt;/code&gt; — sort by multiple properties&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slice&lt;t&gt;&lt;/t&gt;&lt;/strong&gt;: Like Page but without total count — more efficient for infinite scroll (no COUNT query)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: pagination Pages: 1 --&gt;
&lt;svg width=&quot;980pt&quot; height=&quot;128pt&quot; viewBox=&quot;0.00 0.00 980.00 128.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 124.2)&quot;&gt;
&lt;title&gt;pagination&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-124.2 975.74,-124.2 975.74,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- API --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;API&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;145.43,-78 0,-78 0,-26.8 145.43,-26.8 145.43,-78&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;72.71&quot; y=&quot;-63.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;REST API&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;72.71&quot; y=&quot;-48.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/users?page=0&amp;#x26;size=20&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;72.71&quot; y=&quot;-34.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;&amp;#x26;sort=lastName,asc&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REPO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;292.15,-70.8 181.43,-70.8 181.43,-34 292.15,-34 292.15,-70.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;236.79&quot; y=&quot;-56&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;236.79&quot; y=&quot;-41.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;.findAll(Pageable)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- API&amp;#45;&amp;gt;REPO --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;API-&gt;REPO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M145.75,-52.4C153.7,-52.4 161.77,-52.4 169.64,-52.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;169.49,-55.9 179.49,-52.4 169.49,-48.9 169.49,-55.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAGEABLE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAGEABLE&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;464.23,-70.8 328.15,-70.8 328.15,-34 464.23,-34 464.23,-70.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;396.19&quot; y=&quot;-56&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;PageRequest.of(0, 20,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;396.19&quot; y=&quot;-41.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Sort.by(&quot;lastName&quot;))&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;PAGEABLE --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;PAGEABLE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M292.4,-52.4C300.18,-52.4 308.32,-52.4 316.45,-52.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;316.4,-55.9 326.4,-52.4 316.4,-48.9 316.4,-55.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- QUERY --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;QUERY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;665.62,-120.2 500.23,-120.2 500.23,-54.6 665.62,-54.6 665.62,-120.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-105.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SQL Generated:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-91&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SELECT * FROM users&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-76.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ORDER BY last_name ASC&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-62.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;LIMIT 20 OFFSET 0&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAGEABLE&amp;#45;&amp;gt;QUERY --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAGEABLE-&gt;QUERY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M464.67,-65.18C472.53,-66.67 480.66,-68.21 488.79,-69.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;487.9,-73.15 498.38,-71.57 489.21,-66.27 487.9,-73.15&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COUNT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COUNT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;643.59,-36.8 522.25,-36.8 522.25,0 643.59,0 643.59,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SELECT COUNT(*)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;582.92&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;FROM users&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAGEABLE&amp;#45;&amp;gt;COUNT --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAGEABLE-&gt;COUNT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M464.67,-39.98C479.76,-37.2 495.82,-34.25 511.04,-31.45&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;511.27,-34.96 520.47,-29.71 510.01,-28.08 511.27,-34.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAGE --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAGE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;817.01,-85.2 701.62,-85.2 701.62,-19.6 817.01,-19.6 817.01,-85.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;759.31&quot; y=&quot;-70.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Page&amp;#x3C;User&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;759.31&quot; y=&quot;-56&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;content [20 users]&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;759.31&quot; y=&quot;-41.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;totalElements: 156&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;759.31&quot; y=&quot;-27.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;totalPages: 8&lt;/text&gt;
&lt;/g&gt;
&lt;!-- QUERY&amp;#45;&amp;gt;PAGE --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;QUERY-&gt;PAGE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M666.01,-70.92C674.12,-69.3 682.28,-67.66 690.23,-66.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;690.68,-69.54 699.79,-64.14 689.3,-62.68 690.68,-69.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COUNT&amp;#45;&amp;gt;PAGE --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COUNT-&gt;PAGE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M643.94,-30.1C658.84,-33.01 674.93,-36.14 690.19,-39.12&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;689.16,-42.48 699.64,-40.96 690.5,-35.61 689.16,-42.48&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;971.74,-92.4 853.01,-92.4 853.01,-12.4 971.74,-12.4 971.74,-92.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;912.37&quot; y=&quot;-77.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JSON Response&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;912.37&quot; y=&quot;-63.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;{ content: [...],&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;912.37&quot; y=&quot;-48.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;totalElements: 156,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;912.37&quot; y=&quot;-34.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;totalPages: 8,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;912.37&quot; y=&quot;-20&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;number: 0 }&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAGE&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAGE-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M817.42,-52.4C825.26,-52.4 833.38,-52.4 841.41,-52.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;841.16,-55.9 851.16,-52.4 841.16,-48.9 841.16,-55.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Pageable&lt;/strong&gt;: Standard parameter for pagination — page number, page size, sort&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Page&lt;t&gt;&lt;/t&gt;&lt;/strong&gt;: Full result with content + metadata (total elements, total pages, etc.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slice&lt;t&gt;&lt;/t&gt;&lt;/strong&gt;: Lightweight result with just content + navigation info (hasNext, hasPrevious)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort&lt;/strong&gt;: Multi-property sorting with direction (ASC/DESC) and null handling&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default values&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PageableDefault(size=20, sort=&quot;id&quot;, direction=ASC)&lt;/code&gt; for controller parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unpaged&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Pageable.unpaged()&lt;/code&gt; — return all results without pagination&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Pagination and sorting are built into Spring Data’s repository abstraction&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../jpa-repository&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-repository&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JpaRepository&lt;/a&gt; — PagingAndSortingRepository provides the findAll(Pageable) method&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-query-methods&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-query-methods&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Query Methods&lt;/a&gt; — Derived query methods can accept Pageable: &lt;code class=&quot;notranslate&quot;&gt;findByLastName(String, Pageable)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-arraylist&quot; class=&quot;internal alias&quot; data-slug=&quot;java-arraylist&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java ArrayList&lt;/a&gt; — Page’s getContent() returns a List, typically backed by ArrayList&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;OFFSET performance&lt;/strong&gt;: Large offsets (&lt;code class=&quot;notranslate&quot;&gt;page=100&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;size=20&lt;/code&gt; → OFFSET 2000) are slow — use keyset pagination for deep pages&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;COUNT query cost&lt;/strong&gt;: COUNT(*) on large tables can be expensive — consider Slice (no COUNT) for infinite scroll&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort injection&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Sort.by(&quot;lastName&quot;)&lt;/code&gt; — property names are validated, not directly interpolated; but still validate user input for sort fields&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sort direction&lt;/strong&gt;: Default is ASC; specify &lt;code class=&quot;notranslate&quot;&gt;.descending()&lt;/code&gt; for descending&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0-indexed pages&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;page=0&lt;/code&gt; is the first page — this often confuses frontend developers who expect 1-indexed pages&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>jpa-query-methods</title>
    <link href="https://animishraa05.github.io/wiki/java3/jpa-query-methods" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/jpa-query-methods.md" />
    <summary>The Problem Every data access operation that isn’t a basic CRUD operation requires writing a query.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Every data access operation that isn’t a basic CRUD operation requires writing a query. Defining, testing, and maintaining dozens of custom queries for every entity creates significant boilerplate and couples repository code to the query implementation.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Data JPA’s derived query methods generate database queries automatically from method names. A method like &lt;code class=&quot;notranslate&quot;&gt;findByLastNameAndAgeGreaterThan(String lastName, int age)&lt;/code&gt; is parsed and translated into the corresponding JPQL query at startup, eliminating the need for manual query definitions for standard operations.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Method name parsing&lt;/strong&gt;: Spring Data parses &lt;code class=&quot;notranslate&quot;&gt;findBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;readBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;countBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;deleteBy&lt;/code&gt; as the action prefix&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Property references&lt;/strong&gt;: The parser extracts entity property names from the method name (e.g., &lt;code class=&quot;notranslate&quot;&gt;LastName&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;Age&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Criteria keywords&lt;/strong&gt;: AND, OR, Between, LessThan, GreaterThan, Like, In, IgnoreCase, OrderBy, Null, NotNull&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nested property traversal&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findByAddressZipCode(String zip)&lt;/code&gt; traverses the Address→zipCode path&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Startup validation&lt;/strong&gt;: At application startup, Spring Data validates that all properties in method names actually exist — errors are caught early&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Query override&lt;/strong&gt;: If a method name can’t express the logic, &lt;code class=&quot;notranslate&quot;&gt;@Query(&quot;...&quot;)&lt;/code&gt; provides explicit JPQL&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: query_methods Pages: 1 --&gt;
&lt;svg width=&quot;875pt&quot; height=&quot;88pt&quot; viewBox=&quot;0.00 0.00 875.00 88.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 84)&quot;&gt;
&lt;title&gt;query_methods&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-84 870.91,-84 870.91,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- METHOD --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;METHOD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;214.78,-58.4 0,-58.4 0,-21.6 214.78,-21.6 214.78,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;107.39&quot; y=&quot;-43.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;findByLastNameAndAgeGreaterThan&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;107.39&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(String lastName, int age)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PARSER --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PARSER&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;338.13,-58.4 250.78,-58.4 250.78,-21.6 338.13,-21.6 338.13,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;294.46&quot; y=&quot;-43.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Data&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;294.46&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Query Parser&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METHOD&amp;#45;&amp;gt;PARSER --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METHOD-&gt;PARSER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M215.24,-40C223.34,-40 231.29,-40 238.83,-40&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;238.8,-43.5 248.8,-40 238.8,-36.5 238.8,-43.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TOKENS --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TOKENS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;515.84,-80 374.13,-80 374.13,0 515.84,0 515.84,-80&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;444.99&quot; y=&quot;-65.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Parsed Tokens:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;444.99&quot; y=&quot;-50.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SELECT&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;444.99&quot; y=&quot;-36.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;FROM User&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;444.99&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;WHERE lastName = ?1&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;444.99&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;AND age &gt; ?2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PARSER&amp;#45;&amp;gt;TOKENS --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PARSER-&gt;TOKENS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M338.42,-40C346.02,-40 354.15,-40 362.41,-40&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;362.19,-43.5 372.19,-40 362.19,-36.5 362.19,-43.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JPQL --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JPQL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;744.23,-72.8 551.84,-72.8 551.84,-7.2 744.23,-7.2 744.23,-72.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;648.03&quot; y=&quot;-58&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Generated JPQL&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;648.03&quot; y=&quot;-43.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SELECT u FROM User u&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;648.03&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;WHERE u.lastName = :lastName&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;648.03&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;AND u.age &gt; :age&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TOKENS&amp;#45;&amp;gt;JPQL --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TOKENS-&gt;JPQL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M516.3,-40C524.08,-40 532.12,-40 540.21,-40&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;540.15,-43.5 550.15,-40 540.15,-36.5 540.15,-43.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;866.91,-58.4 780.23,-58.4 780.23,-21.6 866.91,-21.6 866.91,-58.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;823.57&quot; y=&quot;-43.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;823.57&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(query result)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JPQL&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JPQL-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M744.69,-40C752.83,-40 760.86,-40 768.5,-40&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;768.24,-43.5 778.24,-40 768.23,-36.5 768.24,-43.5&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Supported prefixes&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;readBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;getBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;queryBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;countBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;deleteBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;removeBy&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Criteria keywords&lt;/strong&gt;: And, Or, Between, LessThan, GreaterThan, Like, NotLike, In, NotIn, IgnoreCase, OrderBy, True, False, Null, NotNull, Before, After, StartingWith, EndingWith, Containing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limiting results&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findFirst5By...&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findTop10By...&lt;/code&gt; — restricts result count&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Return types&lt;/strong&gt;: Entity, &lt;code class=&quot;notranslate&quot;&gt;Optional&amp;#x3C;T&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;List&amp;#x3C;T&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;Stream&amp;#x3C;T&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;T&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;Slice&amp;#x3C;T&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validation&lt;/strong&gt;: Startup validation catches method names that reference non-existent properties&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Derived query methods are a core feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../jpa-repository&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-repository&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JpaRepository&lt;/a&gt; — Derived methods are declared on JpaRepository interfaces&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../hql&quot; class=&quot;internal alias&quot; data-slug=&quot;hql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Query Language&lt;/a&gt; — Both generate JPQL; derived methods are a higher-level abstraction&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-ql&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-ql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Query Language (EJB-QL)&lt;/a&gt; — EJB-QL is written in deployment descriptors; Spring Data derives queries from method names&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Method name explosion&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findByLastNameAndAgeGreaterThanAndStatusInOrderByLastNameAsc(...)&lt;/code&gt; — unreadable; use &lt;code class=&quot;notranslate&quot;&gt;@Query&lt;/code&gt; for complex cases&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distinct&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findDistinctBy...&lt;/code&gt; for distinct results&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;IgnoreCase&lt;/strong&gt;: Works only on String comparisons; added after property: &lt;code class=&quot;notranslate&quot;&gt;findByLastNameIgnoreCase&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nested property ambiguity&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findByAddressZipCode&lt;/code&gt; assumes &lt;code class=&quot;notranslate&quot;&gt;address.zipCode&lt;/code&gt; property; if &lt;code class=&quot;notranslate&quot;&gt;addressZipCode&lt;/code&gt; is a direct property, it won’t find it — disambiguate with &lt;code class=&quot;notranslate&quot;&gt;findByAddress_ZipCode&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>jpa-repository</title>
    <link href="https://animishraa05.github.io/wiki/java3/jpa-repository" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/jpa-repository.md" />
    <summary>The Problem Every data access class needs standard CRUD operations (create, read, update, delete) plus paging and sorting.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Every data access class needs standard CRUD operations (create, read, update, delete) plus paging and sorting. Writing these methods manually for every entity creates repetitive code that adds no business value and introduces bugs in transaction management, connection handling, and result mapping.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;&lt;code class=&quot;notranslate&quot;&gt;JpaRepository&amp;#x3C;T, ID&gt;&lt;/code&gt; is a Spring Data JPA interface that provides a full set of CRUD, paging, and sorting operations automatically. By extending it, a repository interface inherits &lt;code class=&quot;notranslate&quot;&gt;findAll()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findById()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;save()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;delete()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findAll(Pageable)&lt;/code&gt;, and more — no implementation code required. Spring Data generates the implementation at runtime.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Interface hierarchy&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Repository&lt;/code&gt; (marker) → &lt;code class=&quot;notranslate&quot;&gt;CrudRepository&lt;/code&gt; (basic CRUD) → &lt;code class=&quot;notranslate&quot;&gt;PagingAndSortingRepository&lt;/code&gt; (pagination) → &lt;code class=&quot;notranslate&quot;&gt;JpaRepository&lt;/code&gt; (JPA-specific: flush, batch)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CrudRepository&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;save(S entity)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findById(ID id)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findAll()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;count()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;deleteById(ID id)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;existsById(ID id)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PagingAndSortingRepository&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findAll(Pageable)&lt;/code&gt; → returns &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;T&gt;&lt;/code&gt; with total count; &lt;code class=&quot;notranslate&quot;&gt;findAll(Sort)&lt;/code&gt; → returns sorted &lt;code class=&quot;notranslate&quot;&gt;List&amp;#x3C;T&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JpaRepository additions&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findAll()&lt;/code&gt; returns &lt;code class=&quot;notranslate&quot;&gt;List&amp;#x3C;T&gt;&lt;/code&gt; (vs Iterable in CrudRepository), &lt;code class=&quot;notranslate&quot;&gt;flush()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;saveAndFlush()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;deleteInBatch()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;getById()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Runtime proxy&lt;/strong&gt;: Spring Data creates a JDK dynamic proxy implementing the interface, using &lt;code class=&quot;notranslate&quot;&gt;SimpleJpaRepository&lt;/code&gt; as the default implementation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom methods&lt;/strong&gt;: Declare &lt;code class=&quot;notranslate&quot;&gt;findBy...&lt;/code&gt; methods; Spring Data parses the method name and generates the query&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: jpaRepository_hierarchy Pages: 1 --&gt;
&lt;svg width=&quot;218pt&quot; height=&quot;365pt&quot; viewBox=&quot;0.00 0.00 218.00 365.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 360.8)&quot;&gt;
&lt;title&gt;jpaRepository_hierarchy&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-360.8 214.11,-360.8 214.11,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- REPO --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REPO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;161.74,-356.8 48.37,-356.8 48.37,-320 161.74,-320 161.74,-356.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-342&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Repository&amp;#x3C;T, ID&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-327.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(marker interface)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CRUD --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CRUD&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;178.09,-284 32.02,-284 32.02,-232.8 178.09,-232.8 178.09,-284&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-269.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;CrudRepository&amp;#x3C;T, ID&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-254.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;save, findById, findAll,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-240.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;count, delete, existsById&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;CRUD --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;CRUD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.05,-319.7C105.05,-312.61 105.05,-304.17 105.05,-295.88&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;108.55,-295.94 105.05,-285.94 101.55,-295.94 108.55,-295.94&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PAGING --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PAGING&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;210.11,-196.8 0,-196.8 0,-160 210.11,-160 210.11,-196.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-182&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;PagingAndSortingRepository&amp;#x3C;T, ID&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-167.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;findAll(Pageable), findAll(Sort)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CRUD&amp;#45;&amp;gt;PAGING --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CRUD-&gt;PAGING&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.05,-232.72C105.05,-225.01 105.05,-216.44 105.05,-208.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;108.55,-208.52 105.05,-198.52 101.55,-208.52 108.55,-208.52&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JPA --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JPA&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;173.43,-124 36.68,-124 36.68,-72.8 173.43,-72.8 173.43,-124&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-109.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JpaRepository&amp;#x3C;T, ID&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;flush, saveAndFlush,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;deleteInBatch, getById&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PAGING&amp;#45;&amp;gt;JPA --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PAGING-&gt;JPA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.05,-159.7C105.05,-152.61 105.05,-144.17 105.05,-135.88&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;108.55,-135.94 105.05,-125.94 101.55,-135.94 108.55,-135.94&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- USER --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;USER&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;178.08,-36.8 32.02,-36.8 32.02,0 178.08,0 178.08,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;105.05&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(extends JpaRepository)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JPA&amp;#45;&amp;gt;USER --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JPA-&gt;USER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M105.05,-72.72C105.05,-65.01 105.05,-56.44 105.05,-48.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;108.55,-48.52 105.05,-38.52 101.55,-48.52 108.55,-48.52&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;CrudRepository&lt;/strong&gt;: Base interface with full CRUD — return types are &lt;code class=&quot;notranslate&quot;&gt;Optional&amp;#x3C;T&gt;&lt;/code&gt; for single result&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PagingAndSortingRepository&lt;/strong&gt;: Adds pagination and sorting support&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JpaRepository&lt;/strong&gt;: Extends both with JPA-specific batch operations and flush control&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query by Example&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findAll(Example.of(probe))&lt;/code&gt; — query by example object&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Specification&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;JpaSpecificationExecutor&lt;/code&gt; for dynamic criteria queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@NoRepositoryBean&lt;/strong&gt;: Marker for intermediate interfaces that shouldn’t be instantiated&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — JpaRepository is the primary repository interface&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — SimpleJpaRepository delegates to EntityManager (Hibernate)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-query-methods&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-query-methods&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Query Methods&lt;/a&gt; — Derived query methods extend JpaRepository&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-pagination-sorting&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-pagination-sorting&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Pagination and Sorting&lt;/a&gt; — JpaRepository inherits Pageable support&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../java-jdbc&quot; class=&quot;internal alias&quot; data-slug=&quot;java-jdbc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JDBC&lt;/a&gt; — JDBC requires manual SQL; JpaRepository is declarative&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;save() semantics&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;save()&lt;/code&gt; is both INSERT and UPDATE — Hibernate checks if ID exists; this can cause extra SELECT queries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;getById() vs findById()&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;getById()&lt;/code&gt; returns a reference (proxy, lazy); &lt;code class=&quot;notranslate&quot;&gt;findById()&lt;/code&gt; returns Optional (eager loading)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;deleteInBatch vs deleteAll&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;deleteInBatch()&lt;/code&gt; uses one JPQL DELETE query; &lt;code class=&quot;notranslate&quot;&gt;deleteAll()&lt;/code&gt; loads each entity and calls EntityManager.remove()&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transactional behavior&lt;/strong&gt;: Repository methods are @Transactional(readOnly=true) for reads, @Transactional for writes&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>junit-annotations-lifecycle</title>
    <link href="https://animishraa05.github.io/wiki/java3/junit-annotations-lifecycle" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/junit-annotations-lifecycle.md" />
    <summary>The Problem Tests need setup (creating objects, connecting to databases) and cleanup (closing resources, deleting test data).</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="testing" label="testing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Tests need setup (creating objects, connecting to databases) and cleanup (closing resources, deleting test data). Without lifecycle methods, every test duplicates setup and cleanup code. Different tests may need different setup, and some tests need to be conditionally included or excluded.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;JUnit 5 provides lifecycle annotations that define methods to run before/after all tests and before/after each test. These eliminate duplication and establish a clear fixture lifecycle. &lt;code class=&quot;notranslate&quot;&gt;@Tag&lt;/code&gt; filters which tests run in which environments, and &lt;code class=&quot;notranslate&quot;&gt;@DisplayName&lt;/code&gt; provides readable test descriptions.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@BeforeAll&lt;/strong&gt;: Runs once before any test in the class. Must be static (or use &lt;code class=&quot;notranslate&quot;&gt;@TestInstance(Lifecycle.PER_CLASS)&lt;/code&gt;). Used for expensive setup (DB connection, file system init)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@BeforeEach&lt;/strong&gt;: Runs before each &lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt; method. Used to set up test data, create fresh objects, reset state&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterEach&lt;/strong&gt;: Runs after each &lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt; method (even if the test fails). Used to clean up test data, close resources&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterAll&lt;/strong&gt;: Runs once after all tests. Must be static. Used to close global resources&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Tag&lt;/strong&gt;: Labels tests for filtering — &lt;code class=&quot;notranslate&quot;&gt;@Tag(&quot;slow&quot;)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Tag(&quot;integration&quot;)&lt;/code&gt;. Maven: &lt;code class=&quot;notranslate&quot;&gt;mvn test -Dgroups=&quot;fast&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@DisplayName&lt;/strong&gt;: Human-readable test name in reports and IDE — &lt;code class=&quot;notranslate&quot;&gt;@DisplayName(&quot;should return user when valid ID&quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Disabled&lt;/strong&gt;: Temporarily skip a test (with reason) instead of commenting it out&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph lifecycle_order {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot; fontsize=12]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=10]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CLASS [label=&quot;TestClass&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4ALL [label=&quot;@BeforeAll\nstatic void init()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4_1 [label=&quot;@BeforeEach\nvoid setUp()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST1 [label=&quot;@Test\ntest1()&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT_1 [label=&quot;@AfterEach\nvoid tearDown()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4_2 [label=&quot;@BeforeEach\nvoid setUp()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST2 [label=&quot;@Test\ntest2()&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT_2 [label=&quot;@AfterEach\nvoid tearDown()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFTALL [label=&quot;@AfterAll\nstatic void cleanup()&quot; fillcolor=&quot;#cce5ff&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CLASS -&gt; B4ALL&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4ALL -&gt; B4_1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4_1 -&gt; TEST1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST1 -&gt; AFT_1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT_1 -&gt; B4_2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4_2 -&gt; TEST2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST2 -&gt; AFT_2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT_2 -&gt; AFTALL&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@BeforeAll&lt;/strong&gt;: One-time setup, runs once per test class, must be static&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@BeforeEach&lt;/strong&gt;: Setup before every test, fresh state per test&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterEach&lt;/strong&gt;: Cleanup after every test, runs even if test fails&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterAll&lt;/strong&gt;: One-time teardown, runs once per test class&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Tag&lt;/strong&gt;: Filter tests by category (fast/slow, unit/integration, api/db)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@DisplayName&lt;/strong&gt;: Human-readable names visible in IDE and HTML reports&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Disabled&lt;/strong&gt;: Skip test with a descriptive reason; better than commenting out&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../junit-testing&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-testing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Testing&lt;/a&gt; — Lifecycle annotations are a core part of JUnit 5&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../junit-parameterized-tests&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-parameterized-tests&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Parameterized Tests&lt;/a&gt; — Lifecycle hooks work with parameterized tests too&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-try-catch-finally&quot; class=&quot;internal alias&quot; data-slug=&quot;java-try-catch-finally&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Try-Catch-Finally&lt;/a&gt; — @AfterEach acts like a finally block for each test&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../test-driven-development&quot; class=&quot;internal alias&quot; data-slug=&quot;test-driven-development&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Test-Driven Development&lt;/a&gt; — TDD relies on well-structured test fixtures&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Static @BeforeAll&lt;/strong&gt;: Must be static in default PER_METHOD mode; in PER_CLASS mode, can be instance method&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterEach runs always&lt;/strong&gt;: Even if the test throws an exception, @AfterEach runs (like finally) — but if @AfterEach throws, the test may be masked&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tag inheritance&lt;/strong&gt;: Tags are inherited from parent classes and interfaces&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Disabled vs @Ignore (JUnit 4)&lt;/strong&gt;: JUnit 5 uses @Disabled; JUnit 4 used @Ignore — don’t confuse them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Execution order&lt;/strong&gt;: Tests should not depend on order, but if needed, use @TestMethodOrder(MethodName/OrderAnnotation/Random)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>junit-parameterized-tests</title>
    <link href="https://animishraa05.github.io/wiki/java3/junit-parameterized-tests" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/junit-parameterized-tests.md" />
    <summary>The Problem Testing a method with different inputs requires either writing multiple test methods (one per input) or using loops inside a single test.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="testing" label="testing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Testing a method with different inputs requires either writing multiple test methods (one per input) or using loops inside a single test. Multiple tests are repetitive to write and maintain; loops make it hard to identify which input caused a failure.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;JUnit 5’s &lt;code class=&quot;notranslate&quot;&gt;@ParameterizedTest&lt;/code&gt; allows running the same test method with different arguments. By providing a source of arguments (&lt;code class=&quot;notranslate&quot;&gt;@ValueSource&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@CsvSource&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@MethodSource&lt;/code&gt;), the test runs once per argument set, with each run reported independently — making it easy to see exactly which input failed.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@ParameterizedTest&lt;/strong&gt;: Replaces &lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt; to indicate a parameterized test&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ValueSource&lt;/strong&gt;: Provides literal values (ints, strings) — &lt;code class=&quot;notranslate&quot;&gt;@ValueSource(ints = {1, 2, 3})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@CsvSource&lt;/strong&gt;: Provides comma-separated values for multiple parameters — &lt;code class=&quot;notranslate&quot;&gt;@CsvSource({&quot;1,2,3&quot;, &quot;4,5,9&quot;})&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@MethodSource&lt;/strong&gt;: References a static method that returns a &lt;code class=&quot;notranslate&quot;&gt;Stream&amp;#x3C;Arguments&gt;&lt;/code&gt; — most flexible&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@EnumSource&lt;/strong&gt;: Provides enum constants as test arguments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@CsvFileSource&lt;/strong&gt;: Loads test data from a CSV file on classpath&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@NullSource / @EmptySource&lt;/strong&gt;: Provides null and empty values for edge case testing&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph parameterized {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=LR&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot; fontsize=12]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=10]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST [label=&quot;@ParameterizedTest\nvoid testAdd(int a, int b, int expected)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC [label=&quot;Argument Sources&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  VS [label=&quot;@ValueSource\n(single param)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CS [label=&quot;@CsvSource\n(multi params)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MS [label=&quot;@MethodSource\n(complex args)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ES [label=&quot;@EnumSource\n(enum values)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN [label=&quot;Run 1: (1, 2, 3)\nRun 2: (4, 5, 9)\nRun 3: (0, 0, 0)&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PASS [label=&quot;PASS: 1+2=3&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  FAIL [label=&quot;FAIL: 4+5=9?\n(expected 9, got 8)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST -&gt; SRC&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; VS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; CS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; MS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  SRC -&gt; ES&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  VS -&gt; RUN&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CS -&gt; RUN&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  MS -&gt; RUN&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ES -&gt; RUN&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN -&gt; PASS [label=&quot;test passes&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RUN -&gt; FAIL [label=&quot;test fails&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@ParameterizedTest&lt;/strong&gt;: Replaces &lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt; for tests that take arguments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ValueSource&lt;/strong&gt;: Simple literal values — ints, strings, longs, doubles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@CsvSource&lt;/strong&gt;: Multiple parameters as CSV — supports null values via empty field&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@MethodSource&lt;/strong&gt;: References a factory method returning &lt;code class=&quot;notranslate&quot;&gt;Stream&amp;#x3C;Arguments&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;Arguments[]&lt;/code&gt;, or &lt;code class=&quot;notranslate&quot;&gt;Stream&amp;#x3C;T&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@CsvFileSource&lt;/strong&gt;: Load test data from CSV files (lines = test cases, columns = parameters)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@EnumSource&lt;/strong&gt;: All enum values or a filtered subset&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@NullAndEmptySource&lt;/strong&gt;: Combines both @NullSource and @EmptySource&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom display names&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ParameterizedTest(name = &quot;{index}: add({0}, {1}) = {2}&quot;)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../junit-testing&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-testing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Testing&lt;/a&gt; — Parameterized tests extend JUnit 5’s test capabilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../junit-annotations-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-annotations-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Annotations and Lifecycle&lt;/a&gt; — Lifecycle hooks work with parameterized tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../sql-database&quot; class=&quot;internal alias&quot; data-slug=&quot;sql-database&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;SQL Database&lt;/a&gt; — @CsvSource provides tabular test data, similar to query result sets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../test-driven-development&quot; class=&quot;internal alias&quot; data-slug=&quot;test-driven-development&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Test-Driven Development&lt;/a&gt; — TDD benefits from parameterized tests for boundary value analysis&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;MethodSource must be static&lt;/strong&gt;: Factory methods for @MethodSource must be static (unless PER_CLASS lifecycle)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Type conversion&lt;/strong&gt;: JUnit automatically converts strings to primitives, but custom types need &lt;code class=&quot;notranslate&quot;&gt;@ConvertWith&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;@JavaTimeConversionPattern&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Large CSV files&lt;/strong&gt;: @CsvFileSource for large datasets — but test data in CSV may be harder to maintain than inline&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Argument name in display name&lt;/strong&gt;: Use &lt;code class=&quot;notranslate&quot;&gt;{0}&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;{1}&lt;/code&gt;, etc. in the &lt;code class=&quot;notranslate&quot;&gt;name&lt;/code&gt; attribute of @ParameterizedTest to reference arguments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Null handling&lt;/strong&gt;: Primitive parameters can’t accept null — use &lt;code class=&quot;notranslate&quot;&gt;Integer&lt;/code&gt; instead of &lt;code class=&quot;notranslate&quot;&gt;int&lt;/code&gt; for nullable tests&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>junit-testing</title>
    <link href="https://animishraa05.github.io/wiki/java3/junit-testing" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/junit-testing.md" />
    <summary>The Problem Software defects are inevitable.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="testing" label="testing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Software defects are inevitable. Without a systematic testing approach, bugs are found only during manual testing or in production — making them expensive and time-consuming to fix. Developers need a way to automatically verify that code behaves correctly, especially after changes.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;JUnit is the standard framework for writing and running tests in Java. JUnit 5 (Jupiter) provides annotations for defining tests (&lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt;), lifecycle hooks (&lt;code class=&quot;notranslate&quot;&gt;@BeforeEach&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@AfterEach&lt;/code&gt;), assertions (&lt;code class=&quot;notranslate&quot;&gt;assertEquals&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;assertThrows&lt;/code&gt;), assumptions, and test execution control. It integrates with build tools (Maven, Gradle) and CI/CD pipelines.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Test class&lt;/strong&gt;: A plain Java class containing test methods annotated with &lt;code class=&quot;notranslate&quot;&gt;@Test&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Assertions&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;assertEquals(expected, actual)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;assertTrue(condition)&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;assertThrows(Exception.class, () → code)&lt;/code&gt; — verify results&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lifecycle methods&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@BeforeAll&lt;/code&gt; (once before all tests, static), &lt;code class=&quot;notranslate&quot;&gt;@BeforeEach&lt;/code&gt; (before each test), &lt;code class=&quot;notranslate&quot;&gt;@AfterEach&lt;/code&gt; (after each test), &lt;code class=&quot;notranslate&quot;&gt;@AfterAll&lt;/code&gt; (once after all tests, static)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test runner&lt;/strong&gt;: JUnit discovers test classes (classpath scanning), instantiates a new test instance per method (default behavior), executes lifecycle hooks, runs the test, and reports results&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test suites&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Suite&lt;/code&gt; aggregates multiple test classes into a test suite for batch execution&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Build integration&lt;/strong&gt;: Maven Surefire Plugin runs JUnit tests during the &lt;code class=&quot;notranslate&quot;&gt;test&lt;/code&gt; lifecycle phase&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mockito integration&lt;/strong&gt;: Mockito creates mock objects to isolate the unit under test — &lt;code class=&quot;notranslate&quot;&gt;@Mock&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@InjectMocks&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;when(mock.method()).thenReturn(value)&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph junit_flow {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot; fontsize=12]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=10]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CLASS [label=&quot;Test Class\n(StudentServiceTest)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4ALL [label=&quot;@BeforeAll\n(setup DB connection)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4 [label=&quot;@BeforeEach\n(create test data)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST1 [label=&quot;@Test\ntestAddStudent()&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST2 [label=&quot;@Test\ntestDeleteStudent()&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT [label=&quot;@AfterEach\n(cleanup test data)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFTALL [label=&quot;@AfterAll\n(close DB connection)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ASSERT [label=&quot;Assertions\nassertEquals\nassertNotNull\nassertThrows&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RESULT [label=&quot;Test Result\nPASS / FAIL&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CLASS -&gt; B4ALL&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4ALL -&gt; B4&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4 -&gt; TEST1&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST1 -&gt; ASSERT&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ASSERT -&gt; RESULT&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RESULT -&gt; AFT&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT -&gt; B4 [label=&quot;next test&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  B4 -&gt; TEST2&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  TEST2 -&gt; AFT&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  AFT -&gt; AFTALL [label=&quot;all done&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@Test&lt;/strong&gt;: Marks a method as a test; JUnit discovers and executes it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Assertions&lt;/strong&gt;: Static methods comparing actual vs expected; &lt;code class=&quot;notranslate&quot;&gt;assertAll()&lt;/code&gt; groups multiple assertions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Assumptions&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;assumeTrue()&lt;/code&gt; skips tests when conditions aren’t met (e.g., OS-specific tests)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lifecycle hooks&lt;/strong&gt;: @BeforeAll, @BeforeEach, @AfterEach, @AfterAll for setup/cleanup&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Parameterized tests&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ParameterizedTest&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@ValueSource&lt;/code&gt; / &lt;code class=&quot;notranslate&quot;&gt;@CsvSource&lt;/code&gt; — run same test with different inputs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test templates&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@TestTemplate&lt;/code&gt; for reusable test skeletons (e.g., repeated tests)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TestInfo/TestReporter&lt;/strong&gt;: Injection parameters providing test metadata and reporting&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-try-catch-finally&quot; class=&quot;internal alias&quot; data-slug=&quot;java-try-catch-finally&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Try-Catch-Finally&lt;/a&gt; — Assertions and lifecycle hooks replace manual try-catch error handling&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../junit-annotations-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-annotations-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Annotations and Lifecycle&lt;/a&gt; — The lifecycle annotations and their execution order&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../junit-parameterized-tests&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-parameterized-tests&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Parameterized Tests&lt;/a&gt; — Testing multiple inputs with parameterized tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../test-driven-development&quot; class=&quot;internal alias&quot; data-slug=&quot;test-driven-development&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Test-Driven Development&lt;/a&gt; — TDD uses JUnit as the testing framework&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../java-exception-hierarchy&quot; class=&quot;internal alias&quot; data-slug=&quot;java-exception-hierarchy&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Exception Hierarchy&lt;/a&gt; — Exceptions signal runtime problems; JUnit assertions verify correctness&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Test instance lifecycle&lt;/strong&gt;: Default is PER_METHOD (new instance per test) — &lt;code class=&quot;notranslate&quot;&gt;@TestInstance(Lifecycle.PER_CLASS)&lt;/code&gt; shares instance for stateful tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;assertThrows usage&lt;/strong&gt;: Must wrap the code in a lambda — &lt;code class=&quot;notranslate&quot;&gt;assertThrows(IllegalArgumentException.class, () → obj.method())&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test ordering&lt;/strong&gt;: Tests should be independent — don’t rely on execution order; use &lt;code class=&quot;notranslate&quot;&gt;@TestMethodOrder&lt;/code&gt; if order matters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mockito annotations&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ExtendWith(MockitoExtension.class)&lt;/code&gt; enables @Mock and @InjectMocks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Static methods in tests&lt;/strong&gt;: @BeforeAll and @AfterAll must be static (unless using PER_CLASS lifecycle)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Monolithic vs Microservices Architecture</title>
    <link href="https://animishraa05.github.io/wiki/java3/monolithic-vs-microservices" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/monolithic-vs-microservices.md" />
    <summary>What’s Being Compared Monolithic architecture builds an application as a single deployable unit, while microservices architecture decomposes it into independently deployable services.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="architecture" label="architecture" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;whats-being-compared&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;What’s Being Compared&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#whats-being-compared&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Monolithic architecture builds an application as a single deployable unit, while microservices architecture decomposes it into independently deployable services. The comparison isn’t about which is “better” — it’s about which set of tradeoffs matches the application’s scale, team structure, and operational maturity.&lt;/p&gt;
&lt;h2 id=&quot;the-core-tension&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Core Tension&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-core-tension&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Monoliths optimize for &lt;strong&gt;simplicity&lt;/strong&gt; (one codebase, one deploy, one database) at the cost of &lt;strong&gt;scalability&lt;/strong&gt; and &lt;strong&gt;team autonomy&lt;/strong&gt;. Microservices optimize for &lt;strong&gt;independence&lt;/strong&gt; (independent deploy, scale, teams) at the cost of &lt;strong&gt;operational complexity&lt;/strong&gt; (distributed systems, network latency, data consistency).&lt;/p&gt;
&lt;h2 id=&quot;comparison&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Comparison&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#comparison&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Monolithic&lt;/th&gt;
&lt;th&gt;Microservices&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Deployment&lt;/td&gt;
&lt;td&gt;Single WAR/JAR&lt;/td&gt;
&lt;td&gt;Multiple service JARs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scaling&lt;/td&gt;
&lt;td&gt;Scale entire app&lt;/td&gt;
&lt;td&gt;Scale per service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Team structure&lt;/td&gt;
&lt;td&gt;One team per app&lt;/td&gt;
&lt;td&gt;One team per service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Testing&lt;/td&gt;
&lt;td&gt;Single-process E2E&lt;/td&gt;
&lt;td&gt;Contract tests, E2E across services&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;Single shared DB&lt;/td&gt;
&lt;td&gt;Database per service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inter-service calls&lt;/td&gt;
&lt;td&gt;In-process method calls&lt;/td&gt;
&lt;td&gt;HTTP/REST or message queue&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Data consistency&lt;/td&gt;
&lt;td&gt;ACID transactions&lt;/td&gt;
&lt;td&gt;Eventual consistency / Saga&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Startup time&lt;/td&gt;
&lt;td&gt;Slow (big app)&lt;/td&gt;
&lt;td&gt;Fast (small service)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Operational needs&lt;/td&gt;
&lt;td&gt;Simple (one app to monitor)&lt;/td&gt;
&lt;td&gt;Complex (service discovery, tracing)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fault isolation&lt;/td&gt;
&lt;td&gt;One bug takes down everything&lt;/td&gt;
&lt;td&gt;Failure isolated to one service&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;when-to-choose-monolithic&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;When to Choose Monolithic&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#when-to-choose-monolithic&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Small team (1-10 developers)&lt;/li&gt;
&lt;li&gt;Early-stage product (validating market fit)&lt;/li&gt;
&lt;li&gt;Simple domain with clear boundaries&lt;/li&gt;
&lt;li&gt;Limited DevOps/operations resources&lt;/li&gt;
&lt;li&gt;Startup or MVP phase — get to market fast&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;when-to-choose-microservices&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;When to Choose Microservices&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#when-to-choose-microservices&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Large team (multiple squads)&lt;/li&gt;
&lt;li&gt;Proven product at scale&lt;/li&gt;
&lt;li&gt;Multiple subdomains with clear boundaries&lt;/li&gt;
&lt;li&gt;Mature DevOps practice (CI/CD, monitoring, containers)&lt;/li&gt;
&lt;li&gt;Need to scale different parts independently&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-insight&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Insight&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-insight&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The right architecture depends on &lt;strong&gt;team size&lt;/strong&gt; and &lt;strong&gt;organizational maturity&lt;/strong&gt;, not technology preference. Conway’s Law applies: the architecture mirrors the communication structure. Start with a modular monolith (well-organized single deployable); extract microservices only when the monolith’s constraints outweigh microservices’ complexity. Most successful microservice adoptions started as monoliths.&lt;/p&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — Implementation of microservice architecture in Java&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../api-gateway-pattern&quot; class=&quot;internal alias&quot; data-slug=&quot;api-gateway-pattern&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;API Gateway Pattern&lt;/a&gt; — Entry point for microservice requests&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../service-discovery-registry&quot; class=&quot;internal alias&quot; data-slug=&quot;service-discovery-registry&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Service Discovery and Registry&lt;/a&gt; — Dynamic service location in microservices&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../distributed-tracing&quot; class=&quot;internal alias&quot; data-slug=&quot;distributed-tracing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Distributed Tracing&lt;/a&gt; — Observability across service boundaries&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../backend-architecture&quot; class=&quot;internal alias&quot; data-slug=&quot;backend-architecture&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Backend Architecture&lt;/a&gt; — General backend architecture patterns including monolith&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>service-discovery-registry</title>
    <link href="https://animishraa05.github.io/wiki/java3/service-discovery-registry" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/service-discovery-registry.md" />
    <summary>The Problem In a dynamic microservices environment, service instances start, stop, scale up, and scale down constantly.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="architecture" label="architecture" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In a dynamic microservices environment, service instances start, stop, scale up, and scale down constantly. Clients can’t hard-code IP addresses and ports. Without a discovery mechanism, adding or removing instances requires manual configuration updates, which is error-prone and slow.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Service Discovery and Registry is a pattern where a central registry (Eureka, Consul, ZooKeeper) maintains the network locations of all available service instances. Services register themselves on startup and send heartbeats to stay registered. Clients query the registry to find available instances by logical service name.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Registration&lt;/strong&gt;: Each service instance registers its host, port, health check URL, and metadata with the registry on startup&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heartbeat (renewal)&lt;/strong&gt;: Registered instances periodically send heartbeats (e.g., every 30s) to signal they’re alive&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Eviction&lt;/strong&gt;: The registry evicts instances that miss multiple heartbeats (e.g., 3 missed = 90s)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Discovery&lt;/strong&gt;: Clients query the registry for a service name → get a list of available instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load balancing&lt;/strong&gt;: Client-side load balancer selects one instance (round-robin, least connections)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health checks&lt;/strong&gt;: The registry periodically pings service health endpoints to verify they’re actually healthy&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: service_registry Pages: 1 --&gt;
&lt;svg width=&quot;499pt&quot; height=&quot;302pt&quot; viewBox=&quot;0.00 0.00 499.00 302.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 297.6)&quot;&gt;
&lt;title&gt;service_registry&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-297.6 494.87,-297.6 494.87,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- REG --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REG&lt;/title&gt;
&lt;polygon fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; points=&quot;306.47,-208.8 161.88,-208.8 161.88,-169.6 306.47,-169.6 306.47,-208.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-193.1&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Service Registry&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-177.5&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;(Eureka / Consul / ZK)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LB --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;280.87,-121.6 187.48,-121.6 187.48,-84.8 280.87,-84.8 280.87,-121.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client-Side&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Load Balancer&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REG&amp;#45;&amp;gt;LB --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REG-&gt;LB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M234.18,-169.14C234.18,-158.54 234.18,-145.13 234.18,-133.24&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;237.68,-133.55 234.18,-123.55 230.68,-133.55 237.68,-133.55&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.3&quot; y=&quot;-142.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;instance list&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;I1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;158.37,-36.8 29.98,-36.8 29.98,0 158.37,0 158.37,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;94.18&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Instance A&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;94.18&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(register + heartbeat)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I1&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I1-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M59.89,-37.17C26.78,-56.76 -15.43,-89.74 6.05,-121.6 22.59,-146.15 92.27,-164.1 150.32,-175.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;149.42,-178.53 159.89,-176.91 150.69,-171.65 149.42,-178.53&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;39.11&quot; y=&quot;-100.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;POST /register&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I1&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I1-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M90.9,-36.99C87.83,-58.8 85.98,-96.21 103.13,-121.6 115.96,-140.6 135.92,-154.46 156.42,-164.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;154.9,-167.61 165.46,-168.57 157.81,-161.24 154.9,-167.61&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;140.65&quot; y=&quot;-100.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;heartbeat /renew&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;I2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;382.37,-36.8 253.98,-36.8 253.98,0 382.37,0 382.37,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;318.18&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Instance B&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;318.18&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(register + heartbeat)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I2&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I2-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M312.85,-36.88C309.31,-63.84 305.43,-116.17 281.18,-151.6 278.63,-155.32 275.56,-158.76 272.23,-161.9&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;270.14,-159.09 264.7,-168.18 274.62,-164.47 270.14,-159.09&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- I2&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I2-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M324.27,-36.88C327.31,-63.84 323.43,-116.17 299.18,-151.6 296.55,-155.43 293.39,-158.95 289.88,-162.17&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;287.96,-159.22 282.33,-168.2 292.33,-164.69 287.96,-159.22&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- I3 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;I3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;298.37,-293.6 169.98,-293.6 169.98,-256.8 298.37,-256.8 298.37,-293.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-278.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Instance C&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.18&quot; y=&quot;-264.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(register + heartbeat)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- I3&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I3-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M228.54,-256.39C227.45,-245.98 227.16,-232.58 227.66,-220.56&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;231.15,-220.88 228.32,-210.67 224.16,-220.41 231.15,-220.88&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- I3&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;I3-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M239.81,-256.39C240.9,-245.98 241.19,-232.58 240.69,-220.56&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;244.19,-220.41 240.03,-210.67 237.2,-220.88 244.19,-220.41&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;436.19,-293.2 346.16,-293.2 346.16,-257.2 436.19,-257.2 436.19,-293.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;391.18&quot; y=&quot;-271.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;REG --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;REG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M345.74,-267.27C322.52,-262.14 294.67,-253.42 273.02,-238.8 264.91,-233.33 257.68,-225.64 251.72,-218&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;254.91,-216.45 246.21,-210.4 249.25,-220.56 254.91,-216.45&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;338.6&quot; y=&quot;-229.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;GET /instances/service-name&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CALL --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CALL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;490.87,-207.2 353.48,-207.2 353.48,-171.2 490.87,-171.2 490.87,-207.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;422.18&quot; y=&quot;-185.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;http://service-name/api&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;CALL --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;CALL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M400.24,-256.81C402.99,-251.15 405.89,-244.79 408.18,-238.8 410.66,-232.28 412.95,-225.13 414.93,-218.36&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;418.23,-219.55 417.53,-208.98 411.48,-217.68 418.23,-219.55&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;I1 --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;I1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.14,-84.44C183.66,-72.32 156.31,-56.15 134.01,-42.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;135.85,-39.98 125.46,-37.9 132.29,-46.01 135.85,-39.98&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;202.02&quot; y=&quot;-57.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;route request&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;I2 --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;I2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M251.99,-84.64C263.6,-73.19 278.96,-58.05 291.96,-45.24&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;294.35,-47.8 299.02,-38.28 289.44,-42.81 294.35,-47.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Service registry&lt;/strong&gt;: Central database mapping service names → instance addresses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-registration&lt;/strong&gt;: Services register themselves (vs third-party registration via a separate process)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heartbeat-based health&lt;/strong&gt;: Periodic renewal signals liveness; eviction on absence&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client-side discovery&lt;/strong&gt;: Client queries registry and selects an instance (common in Spring Cloud)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Server-side discovery&lt;/strong&gt;: Load balancer (Nginx, AWS ALB) queries registry and routes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Caching&lt;/strong&gt;: Clients cache the registry locally to avoid querying on every request&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — Service discovery is essential for dynamic microservice environments&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — Spring Cloud provides Eureka-based service discovery&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-service-discovery&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-service-discovery&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud Service Discovery&lt;/a&gt; — Spring Cloud’s implementation with Eureka&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../api-gateway-pattern&quot; class=&quot;internal alias&quot; data-slug=&quot;api-gateway-pattern&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;API Gateway Pattern&lt;/a&gt; — API Gateway uses service discovery to route requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../dns&quot; class=&quot;internal alias&quot; data-slug=&quot;dns&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DNS&lt;/a&gt; — DNS resolves name → single IP (cached, slow to update); registry returns dynamic, health-filtered instance list&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Stale registry entries&lt;/strong&gt;: Instances that crash without graceful shutdown (kill -9) leave stale entries — heartbeats eventually evict them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Registry SPOF&lt;/strong&gt;: The registry itself must be highly available — run in cluster mode&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cache staleness&lt;/strong&gt;: Client-cached instance lists may point to dead instances — use circuit breakers and retries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bootstrap problem&lt;/strong&gt;: Clients need to know registry location before they can discover services — use well-known DNS or static config&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multi-datacenter&lt;/strong&gt;: Registry should prefer instances in the same datacenter/region (zone affinity) to reduce latency&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>Servlet vs JSP — Web Presentation Technologies Compared</title>
    <link href="https://animishraa05.github.io/wiki/java3/servlet-vs-jsp" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/servlet-vs-jsp.md" />
    <summary>What’s Being Compared Servlets and JSP are both Java web technologies for generating dynamic content, but they differ fundamentally in their orientation: Servlets are Java-centric (HTML embedded in Java code), while JSP is content-centric (Java embedded in HTML).</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;whats-being-compared&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;What’s Being Compared&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#whats-being-compared&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Servlets and JSP are both Java web technologies for generating dynamic content, but they differ fundamentally in their orientation: Servlets are Java-centric (HTML embedded in Java code), while JSP is content-centric (Java embedded in HTML). The choice affects development team composition, maintenance, and separation of concerns.&lt;/p&gt;
&lt;h2 id=&quot;the-core-tension&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Core Tension&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-core-tension&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The tradeoff is between &lt;strong&gt;control&lt;/strong&gt; (Servlets give full programmatic access to HTTP request/response) vs &lt;strong&gt;separation&lt;/strong&gt; (JSP enables non-Java designers to maintain the view layer). Both compile to the same underlying servlet, but the development experience and team skill requirements differ.&lt;/p&gt;
&lt;h2 id=&quot;comparison&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Comparison&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#comparison&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;&lt;a href=&quot;../../servlets&quot; class=&quot;internal alias&quot; data-slug=&quot;servlets&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Servlets&lt;/a&gt;&lt;/th&gt;
&lt;th&gt;&lt;a href=&quot;../../jsp&quot; class=&quot;internal alias&quot; data-slug=&quot;jsp&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JSP&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Nature&lt;/td&gt;
&lt;td&gt;Java class with embedded HTML&lt;/td&gt;
&lt;td&gt;HTML page with embedded Java&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Request processing, business logic, API endpoints&lt;/td&gt;
&lt;td&gt;Presentation, dynamic UI, form display&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java expertise&lt;/td&gt;
&lt;td&gt;Required&lt;/td&gt;
&lt;td&gt;Minimal (EL/JSTL)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Designer-friendly&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compilation&lt;/td&gt;
&lt;td&gt;Direct .class&lt;/td&gt;
&lt;td&gt;JSP→Servlet→.class&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;No translation overhead&lt;/td&gt;
&lt;td&gt;First-access translation delay&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Session management&lt;/td&gt;
&lt;td&gt;HttpSession API&lt;/td&gt;
&lt;td&gt;&lt;code class=&quot;notranslate&quot;&gt;session&lt;/code&gt; implicit object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error handling&lt;/td&gt;
&lt;td&gt;try-catch in Java code&lt;/td&gt;
&lt;td&gt;Error pages via &lt;code class=&quot;notranslate&quot;&gt;page&lt;/code&gt; directive&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Modern use&lt;/td&gt;
&lt;td&gt;REST controllers (Spring MVC/Boot)&lt;/td&gt;
&lt;td&gt;Template engines (Thymeleaf, React)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;when-to-use-servlets&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;When to Use Servlets&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#when-to-use-servlets&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Building REST APIs or web services (return JSON/XML, not HTML)&lt;/li&gt;
&lt;li&gt;Request processing and routing logic&lt;/li&gt;
&lt;li&gt;When the team is Java-heavy and output format is non-HTML&lt;/li&gt;
&lt;li&gt;When you need full control over HTTP response headers and status codes&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;when-to-use-jsp&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;When to Use JSP&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#when-to-use-jsp&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;Generating dynamic HTML pages with complex layouts&lt;/li&gt;
&lt;li&gt;Teams with UI designers who don’t write Java&lt;/li&gt;
&lt;li&gt;Prototyping view-heavy applications quickly&lt;/li&gt;
&lt;li&gt;Legacy enterprise applications with JSP-based views&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-insight&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Insight&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-insight&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Servlets and JSP solve the same problem from opposite directions. In modern Spring applications, the distinction is largely moot: &lt;code class=&quot;notranslate&quot;&gt;@RestController&lt;/code&gt; replaces servlets for APIs, and template engines (Thymeleaf, FreeMarker) replace JSP for views. The underlying lesson — separation of presentation from logic — is what matters, not the specific technology.&lt;/p&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;a href=&quot;../../servlets&quot; class=&quot;internal alias&quot; data-slug=&quot;servlets&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Servlets&lt;/a&gt; — Java-centric web component, compiled directly&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../jsp&quot; class=&quot;internal alias&quot; data-slug=&quot;jsp&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JSP&lt;/a&gt; — HTML-centric web page, compiles to servlet&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../dispatcher-servlet&quot; class=&quot;internal alias&quot; data-slug=&quot;dispatcher-servlet&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DispatcherServlet&lt;/a&gt; — Spring’s front controller unifying request handling&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — Modern equivalent of Servlet for request handling&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Modern web framework that subsumes both Servlet and JSP patterns&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-annotations</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-annotations" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-annotations.md" />
    <summary>The Problem XML-based Spring configuration is verbose. Every bean declaration, property setting, and dependency wiring requires XML elements.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;XML-based Spring configuration is verbose. Every bean declaration, property setting, and dependency wiring requires XML elements. As applications grow, XML files become unwieldy and hard to maintain. Developers need a more concise way to declare and configure beans directly in the code that defines them.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring annotations enable declarative bean definition and configuration directly in Java source code. Stereotype annotations (@Component, @Service, @Repository, @Controller) mark classes as Spring-managed beans. Configuration annotations (@Configuration, @Bean, @ComponentScan) replace XML configuration files with Java classes.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Stereotype annotations&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Component&lt;/code&gt; (generic), &lt;code class=&quot;notranslate&quot;&gt;@Service&lt;/code&gt; (business logic), &lt;code class=&quot;notranslate&quot;&gt;@Repository&lt;/code&gt; (data access), &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt; (web) — all register the class as a Spring bean&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Annotation scanning&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ComponentScan&lt;/code&gt; tells Spring to scan specified packages for stereotype-annotated classes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Java configuration&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Configuration&lt;/code&gt; classes contain &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; methods that return objects to be managed as beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Property injection&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Value(&quot;${property.name}&quot;)&lt;/code&gt; injects values from properties files&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bean definition&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; in &lt;code class=&quot;notranslate&quot;&gt;@Configuration&lt;/code&gt; class defines a bean with full lifecycle control&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conditional beans&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Conditional&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Profile&lt;/code&gt; create beans only when specific conditions are met&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_annotations Pages: 1 --&gt;
&lt;svg width=&quot;498pt&quot; height=&quot;349pt&quot; viewBox=&quot;0.00 0.00 498.00 349.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 344.8)&quot;&gt;
&lt;title&gt;spring_annotations&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-344.8 494.47,-344.8 494.47,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;387.04,-340.8 312.34,-340.8 312.34,-304.8 387.04,-304.8 387.04,-340.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;349.69&quot; y=&quot;-319.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SCAN --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SCAN&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;365.48,-268.8 247.9,-268.8 247.9,-232 365.48,-232 365.48,-268.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;306.69&quot; y=&quot;-254&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ComponentScan&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;306.69&quot; y=&quot;-239.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(package scan)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;SCAN --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;SCAN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M339.06,-304.4C334.34,-296.67 328.67,-287.39 323.41,-278.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;326.48,-277.09 318.28,-270.38 320.51,-280.74 326.48,-277.09&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CFG --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CFG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;490.47,-196 390.91,-196 390.91,-159.2 490.47,-159.2 490.47,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;440.69&quot; y=&quot;-181.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Configuration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;440.69&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;+ @Bean&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;CFG --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;CFG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M360.67,-304.53C376.23,-280.04 404.86,-234.98 423.32,-205.93&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;426.17,-207.98 428.58,-197.66 420.26,-204.22 426.17,-207.98&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- STEREOTYPES --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STEREOTYPES&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;352.07,-195.6 211.31,-195.6 211.31,-159.6 352.07,-159.6 352.07,-195.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;281.69&quot; y=&quot;-174&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Stereotype Annotations&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SCAN&amp;#45;&amp;gt;STEREOTYPES --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SCAN-&gt;STEREOTYPES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M300.38,-231.53C297.69,-223.9 294.48,-214.81 291.48,-206.34&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;294.87,-205.42 288.24,-197.15 288.27,-207.75 294.87,-205.42&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COMP --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COMP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;93.38,-116 0,-116 0,-79.2 93.38,-79.2 93.38,-116&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;46.69&quot; y=&quot;-101.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Component&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;46.69&quot; y=&quot;-86.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(generic bean)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STEREOTYPES&amp;#45;&amp;gt;COMP --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STEREOTYPES-&gt;COMP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M215.17,-159.13C180.91,-149.57 138.68,-136.89 101.69,-123.2 99.63,-122.44 97.54,-121.63 95.43,-120.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;96.87,-117.61 86.29,-117.04 94.2,-124.08 96.87,-117.61&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SERV --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SERV&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;210.37,-116 111.01,-116 111.01,-79.2 210.37,-79.2 210.37,-116&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;160.69&quot; y=&quot;-101.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;160.69&quot; y=&quot;-86.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(business logic)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STEREOTYPES&amp;#45;&amp;gt;SERV --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STEREOTYPES-&gt;SERV&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M254.84,-159.29C238.07,-148.48 216.26,-134.42 197.85,-122.56&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;199.88,-119.7 189.58,-117.22 196.09,-125.58 199.88,-119.7&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- REPO --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REPO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;335.38,-123.2 228,-123.2 228,-72 335.38,-72 335.38,-123.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;281.69&quot; y=&quot;-108.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Repository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;281.69&quot; y=&quot;-94&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(data access)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;281.69&quot; y=&quot;-79.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;sources_count: 2&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STEREOTYPES&amp;#45;&amp;gt;REPO --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STEREOTYPES-&gt;REPO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M281.69,-159.29C281.69,-152.07 281.69,-143.39 281.69,-134.89&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;285.19,-135.07 281.69,-125.07 278.19,-135.07 285.19,-135.07&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;433.79,-116 353.59,-116 353.59,-79.2 433.79,-79.2 433.79,-116&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;393.69&quot; y=&quot;-101.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Controller&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;393.69&quot; y=&quot;-86.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(web)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STEREOTYPES&amp;#45;&amp;gt;CTRL --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STEREOTYPES-&gt;CTRL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M306.55,-159.29C321.99,-148.53 342.06,-134.55 359.05,-122.72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;360.68,-125.86 366.88,-117.27 356.68,-120.11 360.68,-125.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CONTAINER --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONTAINER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;326.71,-36 236.67,-36 236.67,0 326.71,0 326.71,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;281.69&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;IoC Container&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COMP&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COMP-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M84.88,-78.73C90.47,-76.35 96.19,-74.03 101.69,-72 142.54,-56.93 189.81,-43.14 225.65,-33.41&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;226.18,-36.9 234.93,-30.92 224.36,-30.14 226.18,-36.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SERV&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SERV-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M188.45,-78.8C205.17,-68.07 226.66,-54.29 244.8,-42.66&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;246.67,-45.61 253.2,-37.27 242.89,-39.72 246.67,-45.61&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M281.69,-71.62C281.69,-63.97 281.69,-55.5 281.69,-47.62&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;285.19,-47.83 281.69,-37.83 278.19,-47.83 285.19,-47.83&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M367.99,-78.8C352.66,-68.17 332.99,-54.55 316.3,-42.98&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;318.34,-40.13 308.12,-37.31 314.35,-45.89 318.34,-40.13&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge12&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M446.99,-158.77C453.72,-136.28 461.11,-97.46 442.69,-72 419.11,-39.41 374.8,-26.51 338.63,-21.57&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;339.05,-18.09 328.71,-20.41 338.23,-25.05 339.05,-18.09&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Stereotype hierarchy&lt;/strong&gt;: @Service, @Repository, @Controller are specializations of @Component with different semantics&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Component scanning&lt;/strong&gt;: Spring finds annotated classes via classpath scanning — no XML bean declarations needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Java config&lt;/strong&gt;: @Configuration + @Bean replaces XML entirely with compile-time-checked config&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Scope&lt;/strong&gt;: Configures bean scope (singleton, prototype, request, etc.) on the bean class&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Lazy&lt;/strong&gt;: Defers bean initialization until first use instead of at container startup&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Profile&lt;/strong&gt;: Activates beans only in specific environments (dev, test, prod)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — Annotations are a configuration method for the container&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Annotations modernized Spring configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-autowiring&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-autowiring&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Autowiring&lt;/a&gt; — @Autowired works alongside stereotype annotations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — @Controller, @RequestMapping are Spring MVC annotations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — @SpringBootApplication combines @Configuration + @ComponentScan + @EnableAutoConfiguration&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Annotation scan scope&lt;/strong&gt;: Without @ComponentScan pointing to the right package, @Service and friends do nothing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ambiguous stereotypes&lt;/strong&gt;: @Repository adds translation of persistence exceptions; @Service and @Component are functionally identical&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proxy mode&lt;/strong&gt;: Annotations on methods only work when called through the Spring proxy — internal method calls bypass them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Annotation vs XML override&lt;/strong&gt;: XML bean definitions can override annotation-based configurations if both are present&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-aop-advice</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-aop-advice" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-aop-advice.md" />
    <summary>The Problem Cross-cutting concerns need fine-grained control over when they execute — before a method runs, after it completes (success or failure), only on success, only on exception, or wrapping the method entirely.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Cross-cutting concerns need fine-grained control over when they execute — before a method runs, after it completes (success or failure), only on success, only on exception, or wrapping the method entirely. Each timing has different use cases and different access to method parameters, return values, and exceptions.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring AOP provides five advice types that define exactly when aspect code executes relative to the target method: &lt;code class=&quot;notranslate&quot;&gt;@Before&lt;/code&gt; (pre-processing), &lt;code class=&quot;notranslate&quot;&gt;@After&lt;/code&gt; (finally), &lt;code class=&quot;notranslate&quot;&gt;@AfterReturning&lt;/code&gt; (post-processing on success), &lt;code class=&quot;notranslate&quot;&gt;@AfterThrowing&lt;/code&gt; (error handling), and &lt;code class=&quot;notranslate&quot;&gt;@Around&lt;/code&gt; (full control — can skip or modify method execution).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@Before&lt;/strong&gt;: Executes before the target method. Can access method arguments via &lt;code class=&quot;notranslate&quot;&gt;JoinPoint.getArgs()&lt;/code&gt;. Cannot prevent method execution (unlike Around)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@After&lt;/strong&gt;: Executes after the target method completes, regardless of outcome (like finally). Used for cleanup, auditing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterReturning&lt;/strong&gt;: Executes after successful return. Can access the return value via &lt;code class=&quot;notranslate&quot;&gt;returning&lt;/code&gt; attribute. Not called if method throws&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterThrowing&lt;/strong&gt;: Executes when the target method throws an exception. Can access the exception via &lt;code class=&quot;notranslate&quot;&gt;throwing&lt;/code&gt; attribute&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Around&lt;/strong&gt;: Most powerful. Wraps the target method entirely. &lt;code class=&quot;notranslate&quot;&gt;ProceedingJoinPoint.proceed()&lt;/code&gt; invokes the target. Can modify arguments, catch exceptions, change return value, skip execution entirely&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: advice_types Pages: 1 --&gt;
&lt;svg width=&quot;375pt&quot; height=&quot;497pt&quot; viewBox=&quot;0.00 0.00 375.00 497.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 493)&quot;&gt;
&lt;title&gt;advice_types&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-493 371.48,-493 371.48,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- START --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;START&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;244.45,-489 164.42,-489 164.42,-453 244.45,-453 244.45,-489&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-467.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Method Call&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BEFORE --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEFORE&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;256.12,-416 152.76,-416 152.76,-379.2 256.12,-379.2 256.12,-416&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-401.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Before&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-386.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(pre-processing)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- START&amp;#45;&amp;gt;BEFORE --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;START-&gt;BEFORE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.44,-452.72C204.44,-445.25 204.44,-436.31 204.44,-427.87&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;207.94,-427.98 204.44,-417.98 200.94,-427.98 207.94,-427.98&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AROUND --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AROUND&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;242.11,-342.2 166.76,-342.2 166.76,-305.4 242.11,-305.4 242.11,-342.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-327.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Around&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-313&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(proceed())&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BEFORE&amp;#45;&amp;gt;AROUND --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BEFORE-&gt;AROUND&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.44,-378.85C204.44,-371.29 204.44,-362.26 204.44,-353.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;207.94,-353.86 204.44,-343.86 200.94,-353.86 207.94,-353.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- METHOD --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;METHOD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;159.12,-257.4 59.75,-257.4 59.75,-220.6 159.12,-220.6 159.12,-257.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;109.44&quot; y=&quot;-242.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Target Method&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;109.44&quot; y=&quot;-228.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(business logic)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AROUND&amp;#45;&amp;gt;METHOD --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AROUND-&gt;METHOD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M184.29,-305.24C170.91,-293.57 153.12,-278.08 138.25,-265.11&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;140.86,-262.75 131.02,-258.81 136.26,-268.02 140.86,-262.75&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- END --&gt;
&lt;g id=&quot;node10&quot; class=&quot;node&quot;&gt;
&lt;title&gt;END&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;231.44,-257 177.44,-257 177.44,-221 231.44,-221 231.44,-257&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.44&quot; y=&quot;-235.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;END&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AROUND&amp;#45;&amp;gt;END --&gt;
&lt;g id=&quot;edge12&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AROUND-&gt;END&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M204.44,-305.24C204.44,-294.63 204.44,-280.85 204.44,-268.69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;207.94,-268.76 204.44,-258.76 200.94,-268.76 207.94,-268.76&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;241.12&quot; y=&quot;-278.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;(modified) return&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THROW --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;THROW&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;85.79,-183.6 17.09,-183.6 17.09,-147.6 85.79,-147.6 85.79,-183.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.44&quot; y=&quot;-162&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Exception&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METHOD&amp;#45;&amp;gt;THROW --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METHOD-&gt;THROW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M95.1,-220.35C88.36,-212.05 80.18,-201.98 72.73,-192.82&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;75.59,-190.78 66.56,-185.22 70.15,-195.19 75.59,-190.78&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RETURN --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RETURN&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;189.46,-183.6 103.42,-183.6 103.42,-147.6 189.46,-147.6 189.46,-183.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;146.44&quot; y=&quot;-162&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Return Value&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METHOD&amp;#45;&amp;gt;RETURN --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METHOD-&gt;RETURN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M118.58,-220.35C122.66,-212.48 127.56,-203.03 132.11,-194.25&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;135.21,-195.88 136.7,-185.39 128.99,-192.66 135.21,-195.88&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER_T --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AFTER_T&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;102.88,-110.6 0,-110.6 0,-73.8 102.88,-73.8 102.88,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.44&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@AfterThrowing&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.44&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(on exception)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- THROW&amp;#45;&amp;gt;AFTER_T --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;THROW-&gt;AFTER_T&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M51.44,-147.32C51.44,-139.85 51.44,-130.91 51.44,-122.47&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;54.94,-122.58 51.44,-112.58 47.94,-122.58 54.94,-122.58&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER_F --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AFTER_F&lt;/title&gt;
&lt;polygon fill=&quot;#cce5ff&quot; stroke=&quot;black&quot; points=&quot;183.77,-36.8 129.1,-36.8 129.1,0 183.77,0 183.77,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;156.44&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@After&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;156.44&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(finally)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RETURN&amp;#45;&amp;gt;AFTER_F --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RETURN-&gt;AFTER_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M146.52,-147.17C146.73,-128.86 147.38,-99.27 149.44,-73.8 150.11,-65.51 151.13,-56.54 152.2,-48.33&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;155.66,-48.88 153.54,-38.49 148.72,-47.93 155.66,-48.88&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER_R --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AFTER_R&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;264.22,-110.6 158.66,-110.6 158.66,-73.8 264.22,-73.8 264.22,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;211.44&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@AfterReturning&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;211.44&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(on success)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RETURN&amp;#45;&amp;gt;AFTER_R --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RETURN-&gt;AFTER_R&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M162.17,-147.32C169.75,-139 178.99,-128.84 187.42,-119.58&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;190.01,-121.94 194.15,-112.19 184.83,-117.23 190.01,-121.94&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER_F&amp;#45;&amp;gt;AROUND --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AFTER_F-&gt;AROUND&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M183.96,-21.75C223.7,-26.82 292.44,-42.61 292.44,-91.2 292.44,-240 292.44,-240 292.44,-240 292.44,-261.97 292.69,-270.68 278.44,-287.4 271.52,-295.52 262.31,-301.92 252.75,-306.91&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;251.27,-303.73 243.7,-311.14 254.24,-310.07 251.27,-303.73&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;329.96&quot; y=&quot;-168.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;(Around handles&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;329.96&quot; y=&quot;-156.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;return/exception)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AFTER_R&amp;#45;&amp;gt;AFTER_F --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AFTER_R-&gt;AFTER_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M197.84,-73.45C191.52,-65.19 183.86,-55.19 176.85,-46.05&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;179.66,-43.96 170.8,-38.15 174.1,-48.21 179.66,-43.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER_T&amp;#45;&amp;gt;AFTER_F --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AFTER_T-&gt;AFTER_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M77.39,-73.45C90.64,-64.39 106.96,-53.24 121.32,-43.42&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;122.89,-46.58 129.17,-38.05 118.94,-40.8 122.89,-46.58&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@Before&lt;/strong&gt;: Read method args, perform validation or logging. Cannot abort method&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@After&lt;/strong&gt;: Cleanup, audit logging. Runs like finally block&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterReturning&lt;/strong&gt;: Post-process return value (but can’t change it unless using Around). Access via &lt;code class=&quot;notranslate&quot;&gt;returning = &quot;result&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AfterThrowing&lt;/strong&gt;: Log or transform exceptions. Access via &lt;code class=&quot;notranslate&quot;&gt;throwing = &quot;ex&quot;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Around&lt;/strong&gt;: Most flexible — modify args, catch exceptions, change return value, skip execution entirely&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JoinPoint&lt;/strong&gt;: All advice types (except Around) receive JoinPoint; Around receives ProceedingJoinPoint&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-aop&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-aop&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring AOP&lt;/a&gt; — Advice types are the action component of aspects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — AOP advice is a core Spring AOP feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-try-catch-finally&quot; class=&quot;internal alias&quot; data-slug=&quot;java-try-catch-finally&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Try-Catch-Finally&lt;/a&gt; — Advice types mirror structured exception handling patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../declarative-vs-programmatic-transactions&quot; class=&quot;internal alias&quot; data-slug=&quot;declarative-vs-programmatic-transactions&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Declarative Transactions&lt;/a&gt; — @Transactional is implemented via @Around advice&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — Security annotations use @Before/@Around advice for auth checks&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@Around must call proceed()&lt;/strong&gt;: If @Around advice doesn’t call &lt;code class=&quot;notranslate&quot;&gt;proceed()&lt;/code&gt;, the target method never executes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiple aspects&lt;/strong&gt;: Order is controlled by &lt;code class=&quot;notranslate&quot;&gt;@Order&lt;/code&gt; annotation or &lt;code class=&quot;notranslate&quot;&gt;Ordered&lt;/code&gt; interface&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Return value modification&lt;/strong&gt;: @AfterReturning can’t change the return value (only read it); use @Around to wrap and modify&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception swallowing&lt;/strong&gt;: @Around can catch and suppress exceptions — accidentally hiding errors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ProceedingJoinPoint&lt;/strong&gt;: Only available in @Around advice; casting JoinPoint to ProceedingJoinPoint in other advice types throws ClassCastException&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-aop</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-aop" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-aop.md" />
    <summary>The Problem Cross-cutting concerns like logging, transaction management, security checking, and performance monitoring affect many parts of an application.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Cross-cutting concerns like logging, transaction management, security checking, and performance monitoring affect many parts of an application. Without AOP, these concerns are scattered across every method (logging everywhere), tangled with business logic, and hard to maintain consistently.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Aspect-Oriented Programming (AOP) in Spring allows separating cross-cutting concerns from business logic by defining “aspects” that automatically apply behavior at specified “join points.” Spring AOP uses proxy-based weaving (JDK dynamic proxies or CGLIB) to intercept method calls and apply aspects without modifying business code.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Aspect&lt;/strong&gt;: A modularized cross-cutting concern (e.g., &lt;code class=&quot;notranslate&quot;&gt;@Aspect&lt;/code&gt; class with logging logic)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Join point&lt;/strong&gt;: A specific point in program execution — in Spring AOP, always a method invocation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Advice&lt;/strong&gt;: Action taken at a join point — &lt;code class=&quot;notranslate&quot;&gt;@Before&lt;/code&gt; (before method), &lt;code class=&quot;notranslate&quot;&gt;@After&lt;/code&gt; (after, regardless of outcome), &lt;code class=&quot;notranslate&quot;&gt;@AfterReturning&lt;/code&gt; (after success), &lt;code class=&quot;notranslate&quot;&gt;@AfterThrowing&lt;/code&gt; (after exception), &lt;code class=&quot;notranslate&quot;&gt;@Around&lt;/code&gt; (wraps the method)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pointcut&lt;/strong&gt;: Expression that selects join points — &lt;code class=&quot;notranslate&quot;&gt;execution(* com.example.service.*.*(..))&lt;/code&gt; matches all methods in service package&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Weaving&lt;/strong&gt;: Spring creates a proxy of the target object and applies aspects at the matched join points&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proxy modes&lt;/strong&gt;: JDK dynamic proxy (target implements an interface) or CGLIB proxy (target is a concrete class)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_aop Pages: 1 --&gt;
&lt;svg width=&quot;311pt&quot; height=&quot;288pt&quot; viewBox=&quot;0.00 0.00 311.00 288.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 284.2)&quot;&gt;
&lt;title&gt;spring_aop&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-284.2 307.45,-284.2 307.45,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;273.45,-280.2 168.09,-280.2 168.09,-243.4 273.45,-243.4 273.45,-280.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.77&quot; y=&quot;-265.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client Call&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.77&quot; y=&quot;-251&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;service.method()&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROXY --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROXY&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;277.45,-195.4 164.08,-195.4 164.08,-158.6 277.45,-158.6 277.45,-195.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.77&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring AOP Proxy&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;220.77&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(JDK / CGLIB)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;PROXY --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;PROXY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M219.58,-243.16C219.24,-237.49 218.93,-231.18 218.77,-225.4 218.6,-219.38 218.69,-212.93 218.9,-206.79&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;222.39,-207.22 219.37,-197.07 215.4,-206.89 222.39,-207.22&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PROXY&amp;#45;&amp;gt;CLIENT --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROXY-&gt;CLIENT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M220.77,-195.82C220.77,-206.34 220.77,-219.9 220.77,-231.92&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;217.27,-231.73 220.77,-241.73 224.27,-231.73 217.27,-231.73&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;233.83&quot; y=&quot;-216.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;return&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASPECT --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ASPECT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;185.78,-110.6 93.76,-110.6 93.76,-73.8 185.78,-73.8 185.78,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.77&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Aspect&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.77&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(cross-cutting)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROXY&amp;#45;&amp;gt;ASPECT --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROXY-&gt;ASPECT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M203.59,-158.44C192.39,-146.99 177.58,-131.85 165.05,-119.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;167.75,-116.8 158.26,-112.1 162.75,-121.7 167.75,-116.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TARGET --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TARGET&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;303.45,-110.6 204.08,-110.6 204.08,-73.8 303.45,-73.8 303.45,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;253.77&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Target Object&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;253.77&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(business logic)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROXY&amp;#45;&amp;gt;TARGET --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROXY-&gt;TARGET&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M225.11,-158.14C227.53,-149.13 230.85,-138.12 234.77,-128.6 235.8,-126.1 236.95,-123.54 238.17,-121&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;241.23,-122.7 242.68,-112.21 235,-119.51 241.23,-122.7&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEFORE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEFORE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;63.54,-36.8 0,-36.8 0,0 63.54,0 63.54,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;31.77&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Before&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;31.77&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(logging)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASPECT&amp;#45;&amp;gt;BEFORE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ASPECT-&gt;BEFORE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M113.07,-73.45C99.44,-64.39 82.66,-53.24 67.89,-43.42&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;70.06,-40.65 59.79,-38.03 66.18,-46.48 70.06,-40.65&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AROUND --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AROUND&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;197.78,-36.8 81.76,-36.8 81.76,0 197.78,0 197.78,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.77&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Around&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;139.77&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(transaction mgmt)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASPECT&amp;#45;&amp;gt;AROUND --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ASPECT-&gt;AROUND&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M139.77,-73.45C139.77,-65.89 139.77,-56.86 139.77,-48.38&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;143.27,-48.46 139.77,-38.46 136.27,-48.46 143.27,-48.46&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AFTER --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AFTER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;269.77,-36.8 215.77,-36.8 215.77,0 269.77,0 269.77,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;242.77&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@After&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;242.77&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(audit)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ASPECT&amp;#45;&amp;gt;AFTER --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ASPECT-&gt;AFTER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M165.23,-73.45C178.1,-64.48 193.93,-53.45 207.91,-43.7&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;209.8,-46.65 216,-38.06 205.8,-40.91 209.8,-46.65&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TARGET&amp;#45;&amp;gt;PROXY --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TARGET-&gt;PROXY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M246.67,-111.02C242.39,-121.76 236.84,-135.67 231.98,-147.86&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;228.78,-146.45 228.33,-157.03 235.28,-149.04 228.78,-146.45&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.31&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;return&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Proxy-based&lt;/strong&gt;: Spring AOP is proxy-based, not bytecode weaving — applies only to Spring-managed beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Method-level only&lt;/strong&gt;: Only method execution join points; no field access or constructor interception&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@AspectJ support&lt;/strong&gt;: Annotation-based AOP using AspectJ pointcut expression syntax&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pointcut designators&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;execution()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;within()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;this()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;target()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;args()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@annotation()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;XML config (legacy)&lt;/strong&gt;: Spring 1.2 old-style AOP with ProxyFactoryBean and interceptors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto-proxying&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@EnableAspectJAutoProxy&lt;/code&gt; automatically creates proxies for &lt;code class=&quot;notranslate&quot;&gt;@Aspect&lt;/code&gt; beans&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — AOP is a core Spring module&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-aop-advice&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-aop-advice&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring AOP Advice Types&lt;/a&gt; — The different advice types implement aspects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — Security annotations (@PreAuthorize) use Spring AOP&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../declarative-vs-programmatic-transactions&quot; class=&quot;internal alias&quot; data-slug=&quot;declarative-vs-programmatic-transactions&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Declarative Transactions&lt;/a&gt; — @Transactional uses Spring AOP&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-container&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Container&lt;/a&gt; — EJB uses container-managed interception; Spring AOP is proxy-based&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Internal method calls&lt;/strong&gt;: A method within the same class calling another method bypasses the proxy — AOP doesn’t apply&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Final methods&lt;/strong&gt;: CGLIB can’t override final methods — no AOP for final methods on classes without interfaces&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-injection&lt;/strong&gt;: Use &lt;code class=&quot;notranslate&quot;&gt;@Autowired MyService self&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@Lazy&lt;/code&gt; to enable AOP for internal calls&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: @Around advice adds overhead to every matched method — use judiciously&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proxy exposure&lt;/strong&gt;: If the target casts &lt;code class=&quot;notranslate&quot;&gt;this&lt;/code&gt; in its methods, it gets the raw object, not the proxy&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-autowiring</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-autowiring" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-autowiring.md" />
    <summary>The Problem Manually wiring bean dependencies in XML or @Bean methods becomes repetitive and error-prone as the number of beans grows.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Manually wiring bean dependencies in XML or &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; methods becomes repetitive and error-prone as the number of beans grows. Each dependency requires an explicit &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;property&gt;&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; method parameter. Developers want the container to resolve dependencies automatically based on type or name.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Autowiring is Spring’s automatic dependency resolution mechanism. The container inspects a bean’s constructor, setter, or field and automatically provides the matching dependency. The primary modes are: &lt;code class=&quot;notranslate&quot;&gt;byType&lt;/code&gt; (default with &lt;code class=&quot;notranslate&quot;&gt;@Autowired&lt;/code&gt;), &lt;code class=&quot;notranslate&quot;&gt;byName&lt;/code&gt; (matching bean ID to field name), and explicit &lt;code class=&quot;notranslate&quot;&gt;@Qualifier&lt;/code&gt; for disambiguation.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@Autowired field injection&lt;/strong&gt;: Container matches field type to a bean of that type in the context&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constructor injection&lt;/strong&gt; (preferred): Container resolves constructor parameter types and provides matching beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Setter injection&lt;/strong&gt;: Container calls the setter with the resolved dependency after instantiation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disambiguation&lt;/strong&gt;: If multiple beans of the same type exist, &lt;code class=&quot;notranslate&quot;&gt;@Primary&lt;/code&gt; marks the preferred one; &lt;code class=&quot;notranslate&quot;&gt;@Qualifier(&quot;beanName&quot;)&lt;/code&gt; selects by name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optional dependencies&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Autowired(required=false)&lt;/code&gt; — if no bean is found, leaves field as null&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Resource&lt;/strong&gt;: JSR-250 annotation, resolves by bean name (field name) first, then by type&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: autowiring Pages: 1 --&gt;
&lt;svg width=&quot;802pt&quot; height=&quot;155pt&quot; viewBox=&quot;0.00 0.00 802.00 155.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 150.8)&quot;&gt;
&lt;title&gt;autowiring&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-150.8 797.76,-150.8 797.76,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;81.35,-98.8 0,-98.8 0,-62 81.35,-62 81.35,-98.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;40.67&quot; y=&quot;-84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;40.67&quot; y=&quot;-69.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserService&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONTAINER --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONTAINER&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;306.32,-98.4 216.29,-98.4 216.29,-62.4 306.32,-62.4 306.32,-98.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;261.3&quot; y=&quot;-76.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;IoC Container&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;CONTAINER --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;CONTAINER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M81.77,-80.4C116.18,-80.4 166.14,-80.4 204.46,-80.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;204.43,-83.9 214.43,-80.4 204.43,-76.9 204.43,-83.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.82&quot; y=&quot;-83.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;needs UserRepository&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FIELD --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FIELD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;562.82,-146.8 436.78,-146.8 436.78,-110 562.82,-110 562.82,-146.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.8&quot; y=&quot;-132&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Autowired&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.8&quot; y=&quot;-117.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository repo&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONTAINER&amp;#45;&amp;gt;FIELD --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CONTAINER-&gt;FIELD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M306.65,-90.58C312.59,-91.89 318.6,-93.2 324.32,-94.4 357.41,-101.36 394.13,-108.58 425.31,-114.58&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;424.56,-118 435.04,-116.44 425.88,-111.12 424.56,-118&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;367.13&quot; y=&quot;-113.74&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;injects dependency&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BEAN1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEAN1&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;793.76,-94.8 695.07,-94.8 695.07,-58 793.76,-58 793.76,-94.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;744.42&quot; y=&quot;-80&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;744.42&quot; y=&quot;-65.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(primary)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONTAINER&amp;#45;&amp;gt;BEAN1 --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CONTAINER-&gt;BEAN1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M306.7,-80.03C393.44,-79.31 585.43,-77.71 683.39,-76.9&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;683.37,-80.4 693.35,-76.82 683.32,-73.4 683.37,-80.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.8&quot; y=&quot;-81.99&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;type match found&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AMBIG --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AMBIG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;571.66,-44.8 427.94,-44.8 427.94,-8 571.66,-8 571.66,-44.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.8&quot; y=&quot;-30&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Ambiguous?&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;499.8&quot; y=&quot;-15.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Primary or @Qualifier&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONTAINER&amp;#45;&amp;gt;AMBIG --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CONTAINER-&gt;AMBIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M302.51,-61.92C309.67,-59.1 317.14,-56.45 324.32,-54.4 353.88,-45.96 387.03,-39.84 416.43,-35.51&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;416.59,-39.03 426,-34.16 415.61,-32.1 416.59,-39.03&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;367.13&quot; y=&quot;-57.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;if multiple matches&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BEAN2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEAN2&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;793.76,-36.8 695.07,-36.8 695.07,0 793.76,0 793.76,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;744.42&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;744.42&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(test mock)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AMBIG&amp;#45;&amp;gt;BEAN1 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AMBIG-&gt;BEAN1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M572.08,-35.03C604.38,-39.63 642.9,-46.08 677.07,-54.4 679.33,-54.95 681.62,-55.54 683.92,-56.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;682.73,-59.46 693.31,-58.85 684.66,-52.73 682.73,-59.46&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;633.36&quot; y=&quot;-57.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;@Primary selected&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AMBIG&amp;#45;&amp;gt;BEAN2 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AMBIG-&gt;BEAN2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M572.07,-20.33C578.01,-19.96 583.94,-19.64 589.66,-19.4 620.48,-18.09 654.81,-17.76 683.2,-17.79&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;683.05,-21.29 693.06,-17.82 683.07,-14.29 683.05,-21.29&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;633.36&quot; y=&quot;-22.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;@Qualifier selected&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Mode byType&lt;/strong&gt;: Default behavior — Spring matches by field/constructor parameter type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mode byName&lt;/strong&gt;: Matches field name to bean ID (used with &lt;code class=&quot;notranslate&quot;&gt;@Resource&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Primary&lt;/strong&gt;: Marks a bean as the preferred choice when multiple candidates exist&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Qualifier&lt;/strong&gt;: Selects a specific bean by name when type alone is ambiguous&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Constructor injection preferred&lt;/strong&gt;: Immutable dependencies, required by default, better testability&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Field injection&lt;/strong&gt;: Simplest but makes testing harder (no way to set field without reflection)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — Autowiring is the DI resolution mechanism within the container&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Autowiring is a core Spring DI feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-bean-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-bean-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Bean Lifecycle&lt;/a&gt; — Autowiring executes during the dependency injection phase&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-annotations&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-annotations&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Annotations&lt;/a&gt; — @Autowired, @Qualifier, @Primary are Spring annotations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-context&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-context&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Context&lt;/a&gt; — EJB’s JNDI lookup is explicit; Spring autowiring is implicit&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;NoUniqueBeanDefinitionException&lt;/strong&gt;: Multiple beans of same type without @Primary or @Qualifier — the most common autowiring error&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Field injection in unit tests&lt;/strong&gt;: Need reflection or Spring test runner; constructor injection avoids this entirely&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circular dependency with constructor injection&lt;/strong&gt;: Unresolvable — use @Lazy on one side or switch to setter injection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Autowired on final fields&lt;/strong&gt;: Fails because Spring uses reflection to set fields but final fields can’t be set via reflection after construction&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-bean-lifecycle</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-bean-lifecycle" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-bean-lifecycle.md" />
    <summary>The Problem Enterprise applications need fine-grained control over object lifecycle — when objects are created, how they’re initialized, what happens after all dependencies are set, and how they’re cleaned up.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Enterprise applications need fine-grained control over object lifecycle — when objects are created, how they’re initialized, what happens after all dependencies are set, and how they’re cleaned up. Different use cases require different sharing strategies (singleton for stateless services, prototype for stateful objects).&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The Spring Bean Lifecycle defines the birth-to-death phases every managed bean goes through: instantiation → dependency injection → initialization → ready → destruction. Bean scopes determine how long a bean lives and how many instances are created. Custom scopes can be defined for special use cases.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Instantiation&lt;/strong&gt;: Container creates the bean instance via constructor&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dependency injection&lt;/strong&gt;: Container injects dependencies (via constructor, setter, or field)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Awareness callbacks&lt;/strong&gt;: If bean implements &lt;code class=&quot;notranslate&quot;&gt;BeanNameAware&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;BeanFactoryAware&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;ApplicationContextAware&lt;/code&gt;, container calls them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pre-initialization&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;BeanPostProcessor.postProcessBeforeInitialization()&lt;/code&gt; — container-wide hooks&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Initialization&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PostConstruct&lt;/code&gt; method → &lt;code class=&quot;notranslate&quot;&gt;InitializingBean.afterPropertiesSet()&lt;/code&gt; → custom &lt;code class=&quot;notranslate&quot;&gt;init-method&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Post-initialization&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;BeanPostProcessor.postProcessAfterInitialization()&lt;/code&gt; — proxy creation happens here (AOP)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ready&lt;/strong&gt;: Bean is fully initialized and available for use&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Destruction&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PreDestroy&lt;/code&gt; method → &lt;code class=&quot;notranslate&quot;&gt;DisposableBean.destroy()&lt;/code&gt; → custom &lt;code class=&quot;notranslate&quot;&gt;destroy-method&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scopes&lt;/strong&gt;: singleton (one per container), prototype (new per request), request/ session/application (web contexts), custom&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: bean_lifecycle Pages: 1 --&gt;
&lt;svg width=&quot;253pt&quot; height=&quot;610pt&quot; viewBox=&quot;0.00 0.00 253.00 610.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 605.8)&quot;&gt;
&lt;title&gt;bean_lifecycle&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-605.8 248.85,-605.8 248.85,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- INST --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;169.05,-601.8 84.34,-601.8 84.34,-565 169.05,-565 169.05,-601.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;126.7&quot; y=&quot;-587&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;1. Instantiate&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;126.7&quot; y=&quot;-572.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(constructor)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DI --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DI&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;135.06,-528 42.34,-528 42.34,-491.2 135.06,-491.2 135.06,-528&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;88.7&quot; y=&quot;-513.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;2. Inject&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;88.7&quot; y=&quot;-498.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Dependencies&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INST&amp;#45;&amp;gt;DI --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INST-&gt;DI&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M117.3,-564.65C113.07,-556.65 107.97,-547.02 103.26,-538.12&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;106.46,-536.68 98.69,-529.48 100.28,-539.96 106.46,-536.68&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AWARE --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AWARE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;114.71,-454.2 46.69,-454.2 46.69,-417.4 114.71,-417.4 114.71,-454.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;80.7&quot; y=&quot;-439.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;3. Aware&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;80.7&quot; y=&quot;-425&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Callbacks&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DI&amp;#45;&amp;gt;AWARE --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DI-&gt;AWARE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M86.72,-490.85C85.88,-483.29 84.87,-474.26 83.93,-465.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;87.41,-465.4 82.82,-455.85 80.45,-466.17 87.41,-465.4&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PRE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;135.4,-380.4 0,-380.4 0,-343.6 135.4,-343.6 135.4,-380.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-365.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;4. BeanPostProcessor&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-351.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Before Init&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AWARE&amp;#45;&amp;gt;PRE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AWARE-&gt;PRE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M77.48,-417.05C76.1,-409.4 74.44,-400.26 72.89,-391.68&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;76.37,-391.25 71.14,-382.03 69.48,-392.5 76.37,-391.25&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- INIT --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INIT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;119.47,-283.6 15.93,-283.6 15.93,-246.8 119.47,-246.8 119.47,-283.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-268.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;5. Initialize&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-254.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@PostConstruct&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRE&amp;#45;&amp;gt;INIT --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PRE-&gt;INIT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M67.7,-343.17C67.7,-329.66 67.7,-310.82 67.7,-295.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;71.2,-295.46 67.7,-285.46 64.2,-295.46 71.2,-295.46&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- POST --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;POST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;135.4,-209.8 0,-209.8 0,-158.6 135.4,-158.6 135.4,-209.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-195&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;6. BeanPostProcessor&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;After Init&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;67.7&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(AOP proxies)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- INIT&amp;#45;&amp;gt;POST --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;INIT-&gt;POST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M67.7,-246.67C67.7,-239.21 67.7,-230.22 67.7,-221.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;71.2,-221.69 67.7,-211.69 64.2,-221.69 71.2,-221.69&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- READY --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;READY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;117.71,-121.6 53.68,-121.6 53.68,-84.8 117.71,-84.8 117.71,-121.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;85.7&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;7. Ready&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;85.7&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;for Use&lt;/text&gt;
&lt;/g&gt;
&lt;!-- POST&amp;#45;&amp;gt;READY --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;POST-&gt;READY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M73.39,-158.2C75.21,-150.22 77.24,-141.31 79.12,-133.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;82.49,-134.03 81.3,-123.5 75.67,-132.48 82.49,-134.03&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DEST --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DEST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;168.8,-36.8 80.6,-36.8 80.6,0 168.8,0 168.8,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;124.7&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;8. Destroy&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;124.7&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@PreDestroy&lt;/text&gt;
&lt;/g&gt;
&lt;!-- READY&amp;#45;&amp;gt;DEST --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;READY-&gt;DEST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M86.03,-84.38C86.79,-75.18 88.65,-63.98 92.99,-54.8 94.46,-51.69 96.29,-48.66 98.32,-45.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;100.86,-48.19 104.39,-38.19 95.4,-43.81 100.86,-48.19&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;121.34&quot; y=&quot;-57.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;on shutdown&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DEST&amp;#45;&amp;gt;INST --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DEST-&gt;INST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; stroke-dasharray=&quot;1 5&quot; d=&quot;M138.88,-37.06C142.78,-42.52 146.75,-48.71 149.7,-54.8 159.27,-74.57 163.7,-80.23 163.7,-102.2 163.7,-510.6 163.7,-510.6 163.7,-510.6 163.7,-526.58 156.37,-542.56 148.23,-555.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;145.59,-553.03 142.82,-563.26 151.36,-556.99 145.59,-553.03&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.27&quot; y=&quot;-316.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;(same bean class,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;204.27&quot; y=&quot;-304.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;new instance)&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Singleton scope&lt;/strong&gt;: Default; one instance per IoC container; ideal for stateless services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prototype scope&lt;/strong&gt;: New instance every time the bean is requested; use for stateful objects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Web scopes&lt;/strong&gt;: request (one per HTTP request), session (one per HTTP session), application (one per ServletContext)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom scopes&lt;/strong&gt;: Define custom scope logic (e.g., thread-scoped, tenant-scoped) via &lt;code class=&quot;notranslate&quot;&gt;Scope&lt;/code&gt; interface&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BeanPostProcessor&lt;/strong&gt;: Container-wide hooks that run for every bean — critical for AOP proxy creation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lifecycle callbacks&lt;/strong&gt;: Three ways per phase: annotations (@PostConstruct/@PreDestroy), interfaces, custom init/destroy method&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — The container manages the entire bean lifecycle&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Lifecycle management is a core Spring feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-autowiring&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-autowiring&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Autowiring&lt;/a&gt; — Dependency injection occurs during the lifecycle’s second phase&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../ejb-lifecycle-stateless&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-lifecycle-stateless&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Stateless Bean Lifecycle&lt;/a&gt; — EJB containers also manage bean lifecycles, but with different phases&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-lifecycle-stateful&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-lifecycle-stateful&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Stateful Bean Lifecycle&lt;/a&gt; — EJB stateful beans have passivation/activation; Spring beans don’t&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Prototype destruction&lt;/strong&gt;: Container does NOT call destroy() on prototype beans — you must clean them up manually&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circular dependency&lt;/strong&gt;: Constructor injection + circular dependency causes BeanCurrentlyInCreationException; use setter injection or @Lazy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PostConstruct in proxy&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PostConstruct&lt;/code&gt; in a proxy-wrapped bean runs on the target, not the proxy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scope mismatch&lt;/strong&gt;: Injecting a shorter-lived bean (request) into a longer-lived bean (singleton) requires scoped proxy (&lt;code class=&quot;notranslate&quot;&gt;@Scope(proxyMode=ScopedProxyMode.TARGET_CLASS)&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-boot-actuator</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-boot-actuator" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-boot-actuator.md" />
    <summary>The Problem Production applications need runtime visibility: Are they healthy? How much memory are they using? What’s the request rate? Are there active database connections? Without built-in monitoring, developers resort to SSH access, custom scripts, or third-party agents — which are inconsistent ...</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="ops" label="ops" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Production applications need runtime visibility: Are they healthy? How much memory are they using? What’s the request rate? Are there active database connections? Without built-in monitoring, developers resort to SSH access, custom scripts, or third-party agents — which are inconsistent and fragile.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Boot Actuator provides production-ready HTTP endpoints for monitoring and managing Spring Boot applications. Endpoints expose health information, metrics, environment properties, thread dumps, and more. It integrates with Micrometer for exporting metrics to monitoring systems (Prometheus, Graphite, Datadog).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Actuator endpoints&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;/actuator/health&lt;/code&gt; (app health), &lt;code class=&quot;notranslate&quot;&gt;/actuator/metrics&lt;/code&gt; (JVM and app metrics), &lt;code class=&quot;notranslate&quot;&gt;/actuator/info&lt;/code&gt; (custom app info), &lt;code class=&quot;notranslate&quot;&gt;/actuator/env&lt;/code&gt; (environment properties), &lt;code class=&quot;notranslate&quot;&gt;/actuator/loggers&lt;/code&gt; (log level management)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health indicators&lt;/strong&gt;: Built-in indicators check database connectivity, disk space, Redis, Elasticsearch, etc. — all aggregated into the &lt;code class=&quot;notranslate&quot;&gt;/health&lt;/code&gt; response&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Micrometer&lt;/strong&gt;: Actuator’s metrics facade sends metrics to various monitoring systems (Prometheus, Graphite, InfluxDB)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: Actuator endpoints are secured by default (Spring Security integration); sensitive endpoints restricted to authenticated users&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom endpoints&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Endpoint&lt;/code&gt; annotation to create custom actuator endpoints with &lt;code class=&quot;notranslate&quot;&gt;@ReadOperation&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@WriteOperation&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@DeleteOperation&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: actuator Pages: 1 --&gt;
&lt;svg width=&quot;748pt&quot; height=&quot;262pt&quot; viewBox=&quot;0.00 0.00 748.00 262.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 258.4)&quot;&gt;
&lt;title&gt;actuator&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-258.4 744.38,-258.4 744.38,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- BOOT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BOOT&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;414.72,-254.4 273.97,-254.4 273.97,-218.4 414.72,-218.4 414.72,-254.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;344.34&quot; y=&quot;-232.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Boot Application&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ACTUATOR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;400.36,-182.4 288.33,-182.4 288.33,-145.6 400.36,-145.6 400.36,-182.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;344.34&quot; y=&quot;-167.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Actuator&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;344.34&quot; y=&quot;-153.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(HTTP Endpoints)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BOOT&amp;#45;&amp;gt;ACTUATOR --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BOOT-&gt;ACTUATOR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M344.34,-218C344.34,-210.78 344.34,-202.2 344.34,-194.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;347.84,-194.2 344.34,-184.2 340.84,-194.2 347.84,-194.2&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- HEALTH --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HEALTH&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;122.69,-109.6 0,-109.6 0,-72.8 122.69,-72.8 122.69,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/health&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(DB, disk, Redis, ...)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR&amp;#45;&amp;gt;HEALTH --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACTUATOR-&gt;HEALTH&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M288.09,-148.93C243.9,-137.87 182.03,-122.39 134.07,-110.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;135.15,-107.06 124.6,-108.03 133.46,-113.85 135.15,-107.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- METRICS --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;METRICS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;272.01,-109.6 140.68,-109.6 140.68,-72.8 272.01,-72.8 272.01,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/metrics&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(JVM, HTTP, custom)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR&amp;#45;&amp;gt;METRICS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACTUATOR-&gt;METRICS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M309.52,-145.13C291.87,-136.08 270.23,-124.97 251.33,-115.28&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;253,-112.2 242.5,-110.75 249.8,-118.43 253,-112.2&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- INFO --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;INFO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;398.7,-109.6 289.99,-109.6 289.99,-72.8 398.7,-72.8 398.7,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;344.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/info&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;344.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(custom app info)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR&amp;#45;&amp;gt;INFO --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACTUATOR-&gt;INFO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M344.34,-145.13C344.34,-137.87 344.34,-129.28 344.34,-121.17&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;347.84,-121.33 344.34,-111.33 340.84,-121.33 347.84,-121.33&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ENV --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ENV&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;578.38,-109.6 416.31,-109.6 416.31,-72.8 578.38,-72.8 578.38,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;497.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/env&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;497.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(properties, secrets hidden)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR&amp;#45;&amp;gt;ENV --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACTUATOR-&gt;ENV&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M382.95,-145.13C402.79,-135.95 427.18,-124.67 448.34,-114.88&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;449.77,-118.07 457.37,-110.7 446.83,-111.72 449.77,-118.07&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LOGGERS --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LOGGERS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;740.38,-109.6 596.31,-109.6 596.31,-72.8 740.38,-72.8 740.38,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;668.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/loggers&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;668.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(view/change log levels)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACTUATOR&amp;#45;&amp;gt;LOGGERS --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACTUATOR-&gt;LOGGERS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M400.78,-150.67C451.71,-139.54 527.29,-123.02 585.14,-110.38&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;585.6,-113.86 594.62,-108.31 584.1,-107.03 585.6,-113.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ADMIN --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ADMIN&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;140.38,-36.8 0.31,-36.8 0.31,0 140.38,0 140.38,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;70.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Developer / Ops&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;70.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(monitoring dashboard)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HEALTH&amp;#45;&amp;gt;ADMIN --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HEALTH-&gt;ADMIN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M63.61,-72.33C64.54,-65.07 65.63,-56.48 66.66,-48.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;70.12,-48.88 67.91,-38.52 63.18,-48 70.12,-48.88&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PROM --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;246.69,-36.8 165.99,-36.8 165.99,0 246.69,0 246.69,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Prometheus&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;206.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/micrometer&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METRICS&amp;#45;&amp;gt;PROM --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METRICS-&gt;PROM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M206.34,-72.33C206.34,-65.07 206.34,-56.48 206.34,-48.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;209.84,-48.53 206.34,-38.53 202.84,-48.53 209.84,-48.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- METRICS&amp;#45;&amp;gt;ADMIN --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METRICS-&gt;ADMIN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M172.03,-72.33C154.63,-63.28 133.3,-52.17 114.68,-42.48&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;116.48,-39.47 105.99,-37.96 113.25,-45.68 116.48,-39.47&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built-in endpoints&lt;/strong&gt;: 15+ production endpoints (health, metrics, env, loggers, heapdump, threaddump, mappings)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health aggregation&lt;/strong&gt;: Downstream service health indicators aggregated into overall UP/DOWN status&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Micrometer integration&lt;/strong&gt;: Vendor-neutral metrics facade; binders for JVM, CPU, file descriptors, logback, HikariCP&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Audit events&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;AuditEventRepository&lt;/code&gt; captures authentication and other security events&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom info&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;/info&lt;/code&gt; endpoint exposes any properties under &lt;code class=&quot;notranslate&quot;&gt;info.*&lt;/code&gt; in application.properties&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Log level management&lt;/strong&gt;: Change log levels at runtime via POST to &lt;code class=&quot;notranslate&quot;&gt;/actuator/loggers/{name}&lt;/code&gt; — no restart needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Actuator is a Spring Boot module for production monitoring&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-auto-configuration&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-auto-configuration&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Auto-Configuration&lt;/a&gt; — Actuator auto-configures endpoints based on available dependencies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-rest-api&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-rest-api&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot REST API&lt;/a&gt; — Actuator endpoints are themselves REST APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-context&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-context&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Context&lt;/a&gt; — EJB provides programmatic context; Boot Actuator provides HTTP-accessible monitoring&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Sensitive info in /env&lt;/strong&gt;: Environment values containing passwords/keys are sanitized by default; configure additional sanitization keys&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Endpoint exposure&lt;/strong&gt;: By default, only &lt;code class=&quot;notranslate&quot;&gt;/health&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;/info&lt;/code&gt; are exposed via HTTP — use &lt;code class=&quot;notranslate&quot;&gt;management.endpoints.web.exposure.include=*&lt;/code&gt; to expose all&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: Exposing &lt;code class=&quot;notranslate&quot;&gt;/actuator/shutdown&lt;/code&gt; without authentication allows anyone to stop the application&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance impact&lt;/strong&gt;: High-frequency metrics collection (every 1ms) can impact performance; use appropriate export intervals&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Health cascading&lt;/strong&gt;: If a downstream service is DOWN, the application reports DOWN — configure health indicator thresholds&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-boot-auto-configuration</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-boot-auto-configuration" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-boot-auto-configuration.md" />
    <summary>The Problem Spring applications need many infrastructure beans: DataSource, EntityManagerFactory, TransactionManager, DispatcherServlet, ViewResolver, MessageConverter.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring applications need many infrastructure beans: DataSource, EntityManagerFactory, TransactionManager, DispatcherServlet, ViewResolver, MessageConverter. Manually configuring all of them is repetitive, error-prone, and project-specific — the same patterns repeat across every Spring project.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Auto-configuration is Spring Boot’s mechanism for automatically creating and configuring beans based on dependencies on the classpath. It uses &lt;code class=&quot;notranslate&quot;&gt;@Conditional&lt;/code&gt; annotations to apply configuration only when specific classes, beans, or properties are present. Starters are curated dependency descriptors that trigger auto-configuration for a specific technology.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@EnableAutoConfiguration&lt;/strong&gt;: Triggers scanning of &lt;code class=&quot;notranslate&quot;&gt;META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conditional evaluation&lt;/strong&gt;: Each auto-configuration class has &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnClass&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnMissingBean&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnProperty&lt;/code&gt; conditions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Example&lt;/strong&gt;: If &lt;code class=&quot;notranslate&quot;&gt;DataSource&lt;/code&gt; class is on classpath AND no &lt;code class=&quot;notranslate&quot;&gt;DataSource&lt;/code&gt; bean is defined, Boot auto-creates one from &lt;code class=&quot;notranslate&quot;&gt;application.properties&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ConditionalOnClass&lt;/strong&gt;: Configuration applies only if specific classes exist on classpath (e.g., &lt;code class=&quot;notranslate&quot;&gt;HSQL Driver&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ConditionalOnMissingBean&lt;/strong&gt;: Don’t override user-defined beans — user’s &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; takes priority&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ConditionalOnProperty&lt;/strong&gt;: Enable/disable configuration via properties (e.g., &lt;code class=&quot;notranslate&quot;&gt;spring.jpa.hibernate.ddl-auto&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Override mechanism&lt;/strong&gt;: User defines a &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; of the same type → auto-configuration backs off&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: auto_config Pages: 1 --&gt;
&lt;svg width=&quot;727pt&quot; height=&quot;350pt&quot; viewBox=&quot;0.00 0.00 727.00 350.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 345.6)&quot;&gt;
&lt;title&gt;auto_config&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-345.6 722.64,-345.6 722.64,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- STARTER --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STARTER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;442.41,-341.6 281,-341.6 281,-304.8 442.41,-304.8 442.41,-341.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.71&quot; y=&quot;-326.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;spring-boot-starter-data-jpa&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.71&quot; y=&quot;-312.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(on classpath)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SCAN --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SCAN&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;456.42,-268.8 267,-268.8 267,-232 456.42,-232 456.42,-268.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.71&quot; y=&quot;-254&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@EnableAutoConfiguration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.71&quot; y=&quot;-239.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;scans AutoConfiguration.imports&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STARTER&amp;#45;&amp;gt;SCAN --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;STARTER-&gt;SCAN&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M361.71,-304.33C361.71,-297.07 361.71,-288.48 361.71,-280.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;365.21,-280.53 361.71,-270.53 358.21,-280.53 365.21,-280.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- COND --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;COND&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;421.4,-196 302.01,-196 302.01,-160 421.4,-160 421.4,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;361.71&quot; y=&quot;-174.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Conditional Checks&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SCAN&amp;#45;&amp;gt;COND --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SCAN-&gt;COND&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M361.71,-231.64C361.71,-224.3 361.71,-215.61 361.71,-207.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;365.21,-207.54 361.71,-197.54 358.21,-207.54 365.21,-207.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- C1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;C1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;163.41,-124 0,-124 0,-87.2 163.41,-87.2 163.41,-124&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;81.71&quot; y=&quot;-109.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ConditionalOnClass&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;81.71&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DataSource, EntityManager&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COND&amp;#45;&amp;gt;C1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COND-&gt;C1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M301.64,-161.9C261.42,-151.79 207.96,-138.35 163.83,-127.25&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;164.84,-123.89 154.29,-124.85 163.13,-130.68 164.84,-123.89&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- C2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;C2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;354.17,-124 181.24,-124 181.24,-87.2 354.17,-87.2 354.17,-124&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.71&quot; y=&quot;-109.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ConditionalOnMissingBean&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.71&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DataSource, JpaRepository&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COND&amp;#45;&amp;gt;C2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COND-&gt;C2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M338.47,-159.6C327.03,-151.03 313.05,-140.56 300.54,-131.19&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;302.64,-128.39 292.54,-125.2 298.44,-133.99 302.64,-128.39&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- C3 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;C3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;540.76,-124 372.65,-124 372.65,-87.2 540.76,-87.2 540.76,-124&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;456.71&quot; y=&quot;-109.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ConditionalOnProperty&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;456.71&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;spring.jpa.hibernate.ddl-auto&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COND&amp;#45;&amp;gt;C3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COND-&gt;C3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M385.19,-159.6C396.86,-150.95 411.16,-140.35 423.89,-130.91&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;425.67,-133.96 431.62,-125.19 421.5,-128.33 425.67,-133.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- USER --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;USER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;718.64,-123.6 558.77,-123.6 558.77,-87.6 718.64,-87.6 718.64,-123.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;638.71&quot; y=&quot;-102&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User&#039;s @Bean DataSource&lt;/text&gt;
&lt;/g&gt;
&lt;!-- COND&amp;#45;&amp;gt;USER --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;COND-&gt;USER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M421.81,-161.72C462,-151.51 515.33,-137.96 559.04,-126.85&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;559.64,-130.31 568.47,-124.45 557.92,-123.52 559.64,-130.31&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEANS --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEANS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;377.09,-51.2 158.32,-51.2 158.32,0 377.09,0 377.09,-51.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.71&quot; y=&quot;-36.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Auto-Created Beans&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.71&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DataSource, EntityManagerFactory,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;267.71&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;TransactionManager, JpaRepositories&lt;/text&gt;
&lt;/g&gt;
&lt;!-- C1&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;C1-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M124.38,-86.71C146.06,-77.61 172.96,-66.33 197.58,-56.01&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;198.7,-59.33 206.57,-52.24 195.99,-52.88 198.7,-59.33&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- C2&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;C2-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M267.71,-86.9C267.71,-79.81 267.71,-71.37 267.71,-63.08&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;271.21,-63.14 267.71,-53.14 264.21,-63.14 271.21,-63.14&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- C3&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;C3-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M413.34,-86.71C391.32,-77.61 363.98,-66.33 338.97,-56.01&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;340.39,-52.81 329.81,-52.23 337.72,-59.28 340.39,-52.81&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SKIP --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SKIP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;702.74,-44 574.67,-44 574.67,-7.2 702.74,-7.2 702.74,-44&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;638.71&quot; y=&quot;-29.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Auto-config backs off&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;638.71&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(user-defined wins)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- USER&amp;#45;&amp;gt;SKIP --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;USER-&gt;SKIP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M638.71,-87.29C638.71,-78.03 638.71,-66.37 638.71,-55.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;642.21,-55.92 638.71,-45.92 635.21,-55.92 642.21,-55.92&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Conditional annotations&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnClass&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnMissingBean&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnProperty&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ConditionalOnResource&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Starter dependencies&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-web&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-data-jpa&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-security&lt;/code&gt; — each pulls the transitive deps needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto-configuration report&lt;/strong&gt;: Enable &lt;code class=&quot;notranslate&quot;&gt;--debug&lt;/code&gt; to see which auto-configurations applied and which were skipped&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom starter&lt;/strong&gt;: Create &lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-*&lt;/code&gt; with auto-configuration module + starter POM&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Property binding&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ConfigurationProperties&lt;/code&gt; binds properties to structured Java objects&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Auto-configuration is the core feature of Spring Boot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-actuator&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-actuator&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Actuator&lt;/a&gt; — Actuator’s auto-configuration adds health, metrics endpoints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-rest-api&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-rest-api&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot REST API&lt;/a&gt; — Web auto-configuration sets up embedded Tomcat + Jackson + MVC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-deployment-descriptor&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-deployment-descriptor&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Deployment Descriptor&lt;/a&gt; — EJB uses declarative XML; Spring Boot uses classpath-based conditions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Boot auto-configures DataSource and JPA repos&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Hidden configuration&lt;/strong&gt;: Auto-configuration can create beans you didn’t expect — use &lt;code class=&quot;notranslate&quot;&gt;spring-boot:run --debug&lt;/code&gt; to see the report&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Override confusion&lt;/strong&gt;: Simply adding your own &lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; of the same type disables auto-configuration — sometimes intentionally&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Starter conflicts&lt;/strong&gt;: Conflicting starters (e.g., two embedded DBs on classpath) can cause startup failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exclusion&lt;/strong&gt;: Exclude auto-configuration classes with &lt;code class=&quot;notranslate&quot;&gt;@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Auto-configuration evaluation happens at startup — hundreds of conditional checks can slow cold starts&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-boot-rest-api</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-boot-rest-api" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-boot-rest-api.md" />
    <summary>The Problem Modern applications expose APIs for frontend clients, mobile apps, and third-party integrations.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Modern applications expose APIs for frontend clients, mobile apps, and third-party integrations. Building RESTful APIs requires mapping HTTP methods to operations, serializing/deserializing JSON, handling status codes, and managing request/response formats. Without good tooling, this involves significant boilerplate.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Boot makes REST API development effortless by combining &lt;code class=&quot;notranslate&quot;&gt;@RestController&lt;/code&gt; for request handling, auto-configured Jackson for JSON serialization, embedded Tomcat for serving, and Actuator for monitoring. A single &lt;code class=&quot;notranslate&quot;&gt;@SpringBootApplication&lt;/code&gt; class and a few controller methods produce a production-ready REST API.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@RestController&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@ResponseBody&lt;/code&gt; — every method returns data (JSON/XML), not view names&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request mapping&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@GetMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PutMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@DeleteMapping&lt;/code&gt; map HTTP verbs and URLs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request binding&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PathVariable&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@RequestParam&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@RequestBody&lt;/code&gt; bind request data to method parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Response serialization&lt;/strong&gt;: Jackson (auto-configured) serializes Java objects to JSON; &lt;code class=&quot;notranslate&quot;&gt;@JsonIgnore&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@JsonProperty&lt;/code&gt; control output&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Status codes&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ResponseStatus(HttpStatus.CREATED)&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;ResponseEntity&lt;/code&gt; for full control&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception handling&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@RestControllerAdvice&lt;/code&gt; provides consistent JSON error responses across all endpoints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Documentation&lt;/strong&gt;: Spring Boot integrates with Swagger/OpenAPI for auto-generated API docs&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: rest_api Pages: 1 --&gt;
&lt;svg width=&quot;1139pt&quot; height=&quot;120pt&quot; viewBox=&quot;0.00 0.00 1139.00 120.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 116)&quot;&gt;
&lt;title&gt;rest_api&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-116 1135.29,-116 1135.29,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;123.36,-45 0,-45 0,-8.2 123.36,-8.2 123.36,-45&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.68&quot; y=&quot;-30.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.68&quot; y=&quot;-15.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(React, Mobile, curl)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HTTP --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HTTP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;338.46,-108.4 160.36,-108.4 160.36,-42.8 338.46,-42.8 338.46,-108.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;249.41&quot; y=&quot;-93.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Request&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;249.41&quot; y=&quot;-79.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;POST /api/users&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;249.41&quot; y=&quot;-64.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Content-Type: application/json&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;249.41&quot; y=&quot;-50.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Body: {&quot;name&quot;:&quot;John&quot;}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;HTTP --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;HTTP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M123.75,-42.71C131.93,-44.87 140.48,-47.13 149.11,-49.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;148.02,-52.74 158.59,-51.9 149.81,-45.97 148.02,-52.74&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;554.38,-93 375.46,-93 375.46,-56.2 554.38,-56.2 554.38,-93&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;464.92&quot; y=&quot;-78.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@RestController&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;464.92&quot; y=&quot;-63.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@RequestMapping(/api/users)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HTTP&amp;#45;&amp;gt;CTRL --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HTTP-&gt;CTRL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M338.79,-75.19C347.07,-75.15 355.51,-75.11 363.89,-75.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;363.76,-78.57 373.74,-75.02 363.73,-71.57 363.76,-78.57&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- METHOD --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;METHOD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;746.96,-93 591.38,-93 591.38,-56.2 746.96,-56.2 746.96,-93&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;669.17&quot; y=&quot;-78.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@PostMapping&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;669.17&quot; y=&quot;-63.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@RequestBody User user&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;METHOD --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;METHOD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M554.63,-74.6C562.95,-74.6 571.38,-74.6 579.7,-74.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;579.43,-78.1 589.43,-74.6 579.43,-71.1 579.43,-78.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;967.15,-111.6 877.78,-111.6 877.78,-75.6 967.15,-75.6 967.15,-111.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;922.46&quot; y=&quot;-90&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service Layer&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METHOD&amp;#45;&amp;gt;SVC --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METHOD-&gt;SVC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M747.44,-85.83C753.36,-86.5 759.25,-87.1 764.96,-87.6 798.44,-90.53 836.07,-92.03 866.04,-92.8&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;865.95,-96.3 876.03,-93.03 866.11,-89.3 865.95,-96.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1006.95,-51.2 837.97,-51.2 837.97,0 1006.95,0 1006.95,-51.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;922.46&quot; y=&quot;-36.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Response&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;922.46&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;201 Created&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;922.46&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Body: {&quot;id&quot;:1, &quot;name&quot;:&quot;John&quot;}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- METHOD&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;METHOD-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M747.27,-59.57C772.27,-54.69 800.29,-49.23 826.43,-44.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;826.88,-47.61 836.02,-42.26 825.54,-40.74 826.88,-47.61&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC&amp;#45;&amp;gt;METHOD --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC-&gt;METHOD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M877.31,-82.42C859.61,-78.48 838.95,-74.54 819.97,-72.6 795.65,-70.11 789.41,-72.34 764.96,-72.6 762.89,-72.62 760.79,-72.65 758.68,-72.67&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;758.71,-69.17 748.76,-72.82 758.81,-76.17 758.71,-69.17&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;792.46&quot; y=&quot;-75.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;returns User&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REPO&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1131.29,-112 1043.95,-112 1043.95,-75.2 1131.29,-75.2 1131.29,-112&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1087.62&quot; y=&quot;-97.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Repository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1087.62&quot; y=&quot;-82.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(JPA / JDBC)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC&amp;#45;&amp;gt;REPO --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC-&gt;REPO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M967.62,-93.6C987.52,-93.6 1011.23,-93.6 1032.22,-93.6&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;1032.05,-97.1 1042.05,-93.6 1032.05,-90.1 1032.05,-97.1&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP&amp;#45;&amp;gt;CLIENT --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RESP-&gt;CLIENT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M837.74,-20.1C788.89,-17.35 726.07,-14.6 670.17,-14.6 248.41,-14.6 248.41,-14.6 248.41,-14.6 210.96,-14.6 169.35,-17.06 135.03,-19.75&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;134.87,-16.25 125.19,-20.55 135.44,-23.23 134.87,-16.25&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;RESTful mapping&lt;/strong&gt;: One annotation per HTTP verb — &lt;code class=&quot;notranslate&quot;&gt;@GetMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PutMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@DeleteMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PatchMapping&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Content negotiation&lt;/strong&gt;: Jackson serializes to JSON by default; XML if Jackson XML extension is on classpath&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResponseEntity&lt;/strong&gt;: Full control over status, headers, and body — &lt;code class=&quot;notranslate&quot;&gt;ResponseEntity.created(location).body(savedUser)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request validation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; + BindingResult for request body validation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HATEOAS&lt;/strong&gt;: Spring HATEOAS adds link support for hypermedia-driven APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testing&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;MockMvc&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;WebTestClient&lt;/code&gt; for comprehensive REST API testing&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Boot auto-configures the web stack for REST APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — @RestController is a specialized @Controller&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jax-rpc&quot; class=&quot;internal alias&quot; data-slug=&quot;jax-rpc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JAX-RPC&lt;/a&gt; — JAX-RPC is XML-based SOAP; Spring Boot REST is JSON-based, lighter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — REST APIs are the communication backbone of microservices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../http-protocol&quot; class=&quot;internal alias&quot; data-slug=&quot;http-protocol&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;HTTP Protocol&lt;/a&gt; — REST APIs use HTTP semantics (methods, status codes, headers)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Circular references&lt;/strong&gt;: Bidirectional JPA relationships cause infinite JSON serialization — use &lt;code class=&quot;notranslate&quot;&gt;@JsonIgnore&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;@JsonManagedReference&lt;/code&gt;/&lt;code class=&quot;notranslate&quot;&gt;@JsonBackReference&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Global prefix&lt;/strong&gt;: All APIs under &lt;code class=&quot;notranslate&quot;&gt;/api/v1/&lt;/code&gt; — set &lt;code class=&quot;notranslate&quot;&gt;server.servlet.context-path&lt;/code&gt; or use &lt;code class=&quot;notranslate&quot;&gt;RequestMapping&lt;/code&gt; at class level&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Content-type mismatch&lt;/strong&gt;: Client sends wrong Content-Type → 415 Unsupported Media Type&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Versioning&lt;/strong&gt;: URL path versioning (&lt;code class=&quot;notranslate&quot;&gt;/v1/users&lt;/code&gt;) vs header versioning (&lt;code class=&quot;notranslate&quot;&gt;Accept: application/vnd.company.v1+json&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS&lt;/strong&gt;: Browsers block cross-origin requests; &lt;code class=&quot;notranslate&quot;&gt;@CrossOrigin&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;WebMvcConfigurer.addCorsMappings()&lt;/code&gt; to allow&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-boot</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-boot" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-boot.md" />
    <summary>The Problem Setting up a Spring application requires extensive configuration: choosing a servlet container, configuring DispatcherServlet, setting up view resolvers, managing dependency versions, writing XML/Java config — all before writing any business code.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Setting up a Spring application requires extensive configuration: choosing a servlet container, configuring DispatcherServlet, setting up view resolvers, managing dependency versions, writing XML/Java config — all before writing any business code. This setup overhead delays development and varies across projects.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Boot is an opinionated framework on top of Spring that eliminates boilerplate configuration through auto-configuration and starter dependencies. It embeds Tomcat/Jetty/Undertow, provides sensible defaults for all Spring modules, and enables production-ready features (metrics, health checks) with minimal effort.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@SpringBootApplication&lt;/strong&gt;: Combines @Configuration, @ComponentScan, @EnableAutoConfiguration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto-configuration&lt;/strong&gt;: Spring Boot detects libraries on the classpath and automatically configures beans — e.g., if H2 is on classpath, auto-configures a DataSource&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Starters&lt;/strong&gt;: Curated dependency descriptors (&lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-web&lt;/code&gt; includes Spring MVC + embedded Tomcat + Jackson)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Embedded server&lt;/strong&gt;: Application runs as a standalone JAR with embedded Tomcat — no WAR deployment needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Externalized configuration&lt;/strong&gt;: application.properties or application.yml with environment-specific profiles&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Actuator&lt;/strong&gt;: Production endpoints for health, metrics, environment, loggers, thread dumps&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_boot Pages: 1 --&gt;
&lt;svg width=&quot;714pt&quot; height=&quot;190pt&quot; viewBox=&quot;0.00 0.00 714.00 190.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 186.4)&quot;&gt;
&lt;title&gt;spring_boot&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-186.4 710.14,-186.4 710.14,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;444.93,-182.4 298.67,-182.4 298.67,-145.6 444.93,-145.6 444.93,-182.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;371.8&quot; y=&quot;-167.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@SpringBootApplication&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;371.8&quot; y=&quot;-153.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;main()&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTO --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AUTO&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;169.6,-109.6 0,-109.6 0,-72.8 169.6,-72.8 169.6,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;84.8&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Auto-Configuration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;84.8&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(@EnableAutoConfiguration)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;AUTO --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;AUTO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M299.38,-145.13C259.44,-135.28 209.68,-123.01 168.13,-112.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;169.22,-109.42 158.67,-110.42 167.54,-116.22 169.22,-109.42&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- STARTERS --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STARTERS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;187.15,-36.8 56.45,-36.8 56.45,0 187.15,0 187.15,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;121.8&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Starters&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;121.8&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(spring-boot-starter-*)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;STARTERS --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;STARTERS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M299.05,-145.13C272.05,-136.69 241.91,-125.01 216.8,-109.6 196.77,-97.3 195.83,-89.02 178.8,-72.8 169.18,-63.63 158.57,-53.66 149.14,-44.84&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;151.68,-42.42 141.98,-38.15 146.9,-47.54 151.68,-42.42&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EMBED --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EMBED&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;534.15,-109.6 373.45,-109.6 373.45,-72.8 534.15,-72.8 534.15,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;453.8&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Embedded Server&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;453.8&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Tomcat / Jetty / Undertow)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;EMBED --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;EMBED&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M392.49,-145.13C402.21,-136.75 413.95,-126.61 424.55,-117.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;426.69,-120.23 431.97,-111.05 422.11,-114.94 426.69,-120.23&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CFG --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CFG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;355.84,-109.6 225.77,-109.6 225.77,-72.8 355.84,-72.8 355.84,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;290.8&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;application.properties&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;290.8&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/ application.yml&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;CFG --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;CFG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M351.36,-145.13C341.77,-136.75 330.17,-126.61 319.7,-117.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;322.21,-115 312.37,-111.06 317.6,-120.27 322.21,-115&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ACT --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ACT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;689.82,-109.6 551.78,-109.6 551.78,-72.8 689.82,-72.8 689.82,-109.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;620.8&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Actuator&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;620.8&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(/health, /metrics, /info)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;ACT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;ACT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M434.63,-145.13C468.84,-135.41 511.36,-123.32 547.12,-113.15&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;547.87,-116.58 556.53,-110.47 545.96,-109.84 547.87,-116.58&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BIZ --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BIZ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;693.83,-36.8 485.77,-36.8 485.77,0 693.83,0 693.83,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;589.8&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Business Code&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;589.8&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Controllers, Services, Repositories)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;BIZ --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;BIZ&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M445.1,-161.66C531.35,-158.34 666.9,-147.13 698.8,-109.6 709.39,-97.14 707.46,-86.68 698.8,-72.8 690.68,-59.78 678.36,-49.84 664.89,-42.29&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;666.76,-39.32 656.26,-37.9 663.58,-45.56 666.76,-39.32&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AUTO&amp;#45;&amp;gt;STARTERS --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AUTO-&gt;STARTERS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M94.14,-72.33C98.16,-64.65 102.95,-55.48 107.4,-46.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;110.37,-48.84 111.9,-38.36 104.16,-45.6 110.37,-48.84&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EMBED&amp;#45;&amp;gt;BIZ --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EMBED-&gt;BIZ&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M488.12,-72.33C505.52,-63.28 526.84,-52.17 545.47,-42.48&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;546.9,-45.68 554.15,-37.96 543.67,-39.47 546.9,-45.68&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PROFILES --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROFILES&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;340.82,-36.8 240.78,-36.8 240.78,0 340.82,0 340.82,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;290.8&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Profiles&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;290.8&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(dev, test, prod)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;PROFILES --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;PROFILES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M290.8,-72.33C290.8,-65.07 290.8,-56.48 290.8,-48.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;294.3,-48.53 290.8,-38.53 287.3,-48.53 294.3,-48.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Opinionated defaults&lt;/strong&gt;: Sensible configurations chosen automatically based on classpath contents&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Standalone JAR&lt;/strong&gt;: Run with &lt;code class=&quot;notranslate&quot;&gt;java -jar app.jar&lt;/code&gt; — no external web server needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Starters&lt;/strong&gt;: ~50 curated dependency sets; one-liner in build file replaces pages of dependency management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Actuator&lt;/strong&gt;: Built-in production monitoring: health, metrics, environment, loggers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Externalized config&lt;/strong&gt;: Properties, YAML, environment variables, command-line arguments — with precedence order&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spring Boot CLI&lt;/strong&gt;: Groovy-based command-line tool for rapid prototyping (optional)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Spring Boot builds on and auto-configures Spring Framework&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-auto-configuration&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-auto-configuration&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Auto-Configuration&lt;/a&gt; — The auto-configuration mechanism drives Spring Boot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-actuator&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-actuator&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot Actuator&lt;/a&gt; — Actuator provides production monitoring&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot-rest-api&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot-rest-api&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot REST API&lt;/a&gt; — REST APIs are a primary use case for Spring Boot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Spring Boot auto-configures Spring MVC with embedded server&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-jar-file&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-jar-file&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB-JAR File&lt;/a&gt; — EJB requires an application server; Spring Boot is self-contained&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Auto-configuration ignorance&lt;/strong&gt;: Auto-configuration applies conditionally — if you define your own bean, Boot’s default backs off&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fat JAR size&lt;/strong&gt;: Spring Boot executable JARs include all dependencies — can be 20MB+; use Docker layers for efficient deployment&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DevTools&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;spring-boot-devtools&lt;/code&gt; enables live reload but should NEVER be included in production builds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Context path&lt;/strong&gt;: By default, server runs on root context; set &lt;code class=&quot;notranslate&quot;&gt;server.servlet.context-path=/myapp&lt;/code&gt; in properties&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Profile-specific config&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;application-dev.properties&lt;/code&gt; overrides &lt;code class=&quot;notranslate&quot;&gt;application.properties&lt;/code&gt; when &lt;code class=&quot;notranslate&quot;&gt;spring.profiles.active=dev&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-cloud-api-gateway</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-cloud-api-gateway" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-cloud-api-gateway.md" />
    <summary>The Problem In a microservices architecture, clients would need to know the location of every service, handle authentication for each service, and manage cross-cutting concerns (rate limiting, logging) individually.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="cloud" label="cloud" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In a microservices architecture, clients would need to know the location of every service, handle authentication for each service, and manage cross-cutting concerns (rate limiting, logging) individually. This creates tight coupling between clients and services, and duplicates security/observability logic.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Cloud Gateway is an API Gateway built on Spring WebFlux (Reactive). It acts as a single entry point for all client requests, routing them to the appropriate microservice based on path, headers, or other predicates. It handles cross-cutting concerns — authentication, rate limiting, header transformation — in one place.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Route definition&lt;/strong&gt;: Routes match incoming requests using predicates (path, method, header, query param)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Predicate matching&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Path=/users/**&lt;/code&gt; matches all requests starting with &lt;code class=&quot;notranslate&quot;&gt;/users&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filter chains&lt;/strong&gt;: Before routing to the service, the request passes through a filter chain: authentication, rate limiting, header modification&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service routing&lt;/strong&gt;: Gateway forwards the request to the target service (discovered via Eureka or configured URI)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Response filters&lt;/strong&gt;: On the return path, filters modify the response (add headers, transform body)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WebFlux&lt;/strong&gt;: Built on reactive Netty, not Tomcat — non-blocking I/O for high throughput&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: api_gateway Pages: 1 --&gt;
&lt;svg width=&quot;959pt&quot; height=&quot;155pt&quot; viewBox=&quot;0.00 0.00 959.00 155.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 150.8)&quot;&gt;
&lt;title&gt;api_gateway&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-150.8 955.21,-150.8 955.21,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;94.02,-91.8 0,-91.8 0,-55 94.02,-55 94.02,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;47.01&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;47.01&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Mobile / Web)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GATEWAY&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;267.08,-91.8 131.02,-91.8 131.02,-55 267.08,-55 267.08,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;199.05&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Cloud Gateway&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;199.05&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Reactive WebFlux)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;GATEWAY --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;GATEWAY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M94.25,-73.4C102.27,-73.4 110.81,-73.4 119.42,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;119.21,-76.9 129.21,-73.4 119.21,-69.9 119.21,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PRED --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PRED&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;442.16,-91.8 304.08,-91.8 304.08,-55 442.16,-55 442.16,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;373.12&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Predicates&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;373.12&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(path, method, header)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY&amp;#45;&amp;gt;PRED --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GATEWAY-&gt;PRED&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M267.56,-73.4C275.72,-73.4 284.11,-73.4 292.42,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;292.16,-76.9 302.16,-73.4 292.16,-69.9 292.16,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- FILTERS --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FILTERS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;590.53,-99 479.16,-99 479.16,-47.8 590.53,-47.8 590.53,-99&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;534.84&quot; y=&quot;-84.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Filters&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;534.84&quot; y=&quot;-69.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(auth, rate-limit,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;534.84&quot; y=&quot;-55.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;header transform)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PRED&amp;#45;&amp;gt;FILTERS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PRED-&gt;FILTERS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M442.32,-73.4C450.71,-73.4 459.28,-73.4 467.65,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;467.38,-76.9 477.38,-73.4 467.38,-69.9 467.38,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ROUTE --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ROUTE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;732.24,-91.4 627.53,-91.4 627.53,-55.4 732.24,-55.4 732.24,-91.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;679.88&quot; y=&quot;-69.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Route to Service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FILTERS&amp;#45;&amp;gt;ROUTE --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;FILTERS-&gt;ROUTE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M590.74,-73.4C598.97,-73.4 607.51,-73.4 615.9,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;615.68,-76.9 625.68,-73.4 615.68,-69.9 615.68,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC1 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;943.2,-146.8 858.52,-146.8 858.52,-110 943.2,-110 943.2,-146.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-132&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-117.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/api/users/**&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROUTE&amp;#45;&amp;gt;SVC1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ROUTE-&gt;SVC1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M732.5,-86.36C767.07,-95.05 812.44,-106.44 847.22,-115.18&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;846.1,-118.51 856.65,-117.55 847.8,-111.72 846.1,-118.51&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;791.37&quot; y=&quot;-113.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;matched /users&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC2 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;945.87,-91.8 855.85,-91.8 855.85,-55 945.87,-55 945.87,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/api/orders/**&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROUTE&amp;#45;&amp;gt;SVC2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ROUTE-&gt;SVC2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M732.5,-73.4C766.13,-73.4 809.97,-73.4 844.35,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;844.1,-76.9 854.1,-73.4 844.1,-69.9 844.1,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;791.37&quot; y=&quot;-76.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;matched /orders&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC3 --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;951.21,-36.8 850.51,-36.8 850.51,0 951.21,0 951.21,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Product Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;900.86&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/api/products/**&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROUTE&amp;#45;&amp;gt;SVC3 --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ROUTE-&gt;SVC3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M732.5,-60.44C764.42,-52.42 805.55,-42.09 839.05,-33.67&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;839.78,-37.1 848.63,-31.27 838.08,-30.31 839.78,-37.1&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;791.37&quot; y=&quot;-58.61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;matched /products&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Reactive&lt;/strong&gt;: Built on Spring WebFlux, not Servlet API — non-blocking, high concurrency&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Route predicates&lt;/strong&gt;: Path, Method, Header, Query, Cookie, Host, RemoteAddr, Weight&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Filters&lt;/strong&gt;: AddRequestHeader, AddResponseHeader, CircuitBreaker, Retry, RateLimiter, RequestRateLimiter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service discovery integration&lt;/strong&gt;: Automatically resolves service names via Eureka / LoadBalancer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom filters&lt;/strong&gt;: Implement &lt;code class=&quot;notranslate&quot;&gt;GatewayFilter&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;GlobalFilter&lt;/code&gt; interfaces for custom logic&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circuit breaking&lt;/strong&gt;: Integrates with Resilience4j for downstream service failure protection&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — Gateway is a Spring Cloud module for edge services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-service-discovery&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-service-discovery&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud Service Discovery&lt;/a&gt; — Gateway uses Eureka to find service instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Gateway is auto-configured via Spring Boot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — API Gateway is a core component of microservice architecture&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../servlets&quot; class=&quot;internal alias&quot; data-slug=&quot;servlets&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Servlets&lt;/a&gt; — Servlets are blocking I/O; Gateway uses reactive non-blocking WebFlux&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;WebFlux vs MVC&lt;/strong&gt;: Gateway runs on Netty (WebFlux) — can’t use &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;RestTemplate&lt;/code&gt;; use &lt;code class=&quot;notranslate&quot;&gt;WebClient&lt;/code&gt; instead&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;WebSocket support&lt;/strong&gt;: Gateway supports WebSocket proxying via &lt;code class=&quot;notranslate&quot;&gt;ws:&lt;/code&gt; / &lt;code class=&quot;notranslate&quot;&gt;wss:&lt;/code&gt; route URIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS&lt;/strong&gt;: Gateway must handle CORS at the edge — configure &lt;code class=&quot;notranslate&quot;&gt;spring.cloud.gateway.globalcors&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Latency&lt;/strong&gt;: Each filter adds latency — keep filter chains lean&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gateway as SPOF&lt;/strong&gt;: The gateway is a single point of entry — deploy multiple instances behind a load balancer&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-cloud-service-discovery</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-cloud-service-discovery" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-cloud-service-discovery.md" />
    <summary>The Problem In a microservices architecture, service instances come and go dynamically — scaled up, down, or failed.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="cloud" label="cloud" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In a microservices architecture, service instances come and go dynamically — scaled up, down, or failed. Hard-coding service URLs (e.g., &lt;code class=&quot;notranslate&quot;&gt;http://192.168.1.5:8080&lt;/code&gt;) makes the system brittle. Services need a dynamic registry to discover each other’s locations without manual configuration.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Cloud Service Discovery uses a service registry (Netflix Eureka) where each microservice registers its network location on startup and periodically sends heartbeats. Clients query the registry by logical service name (e.g., &lt;code class=&quot;notranslate&quot;&gt;user-service&lt;/code&gt;) to get available instances and distribute requests using client-side load balancing.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Eureka Server&lt;/strong&gt;: A standalone service that maintains a registry of all available service instances. Services register their host, port, health status&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service registration&lt;/strong&gt;: Each microservice, annotated with &lt;code class=&quot;notranslate&quot;&gt;@EnableEurekaClient&lt;/code&gt;, registers with the Eureka server on startup&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heartbeat (renew)&lt;/strong&gt;: Registered services send periodic heartbeats (default 30s) to signal they’re alive. Missed heartbeats → instance is evicted&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service discovery&lt;/strong&gt;: Clients use &lt;code class=&quot;notranslate&quot;&gt;@LoadBalanced RestTemplate&lt;/code&gt; or Spring Cloud OpenFeign to call services by logical name — e.g., &lt;code class=&quot;notranslate&quot;&gt;http://user-service/api/users&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load balancing&lt;/strong&gt;: Spring Cloud LoadBalancer intercepts the logical name, queries Eureka for instances, and selects one (round-robin, random, etc.)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client-side vs Server-side&lt;/strong&gt;: Client-side (Ribbon/LoadBalancer) — client chooses instance; Server-side — load balancer (Nginx, AWS ELB) distributes requests&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: service_discovery Pages: 1 --&gt;
&lt;svg width=&quot;730pt&quot; height=&quot;162pt&quot; viewBox=&quot;0.00 0.00 730.00 162.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 158)&quot;&gt;
&lt;title&gt;service_discovery&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-158 726.19,-158 726.19,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- EUREKA --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EUREKA&lt;/title&gt;
&lt;polygon fill=&quot;#ffd700&quot; stroke=&quot;black&quot; stroke-width=&quot;2&quot; points=&quot;343.58,-98 224.28,-98 224.28,-58.8 343.58,-58.8 343.58,-98&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;283.93&quot; y=&quot;-82.3&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;Eureka Server&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;283.93&quot; y=&quot;-66.7&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;13.00&quot;&gt;(Service Registry)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LB --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;525.22,-101.8 431.83,-101.8 431.83,-65 525.22,-65 525.22,-101.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;478.52&quot; y=&quot;-87&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Load Balancer&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;478.52&quot; y=&quot;-72.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(round-robin)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- EUREKA&amp;#45;&amp;gt;LB --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EUREKA-&gt;LB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M344.02,-79.93C368.16,-80.56 395.98,-81.28 419.96,-81.91&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;419.78,-85.4 429.87,-82.16 419.97,-78.4 419.78,-85.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;387.7&quot; y=&quot;-84.64&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;instance list&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1 --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;722.19,-77 601.79,-77 601.79,-25.8 722.19,-25.8 722.19,-77&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-62.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User-Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-47.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(instance 1)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-33.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;register + heartbeat&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC1-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M601.53,-47.67C577.8,-46.36 550.23,-45.04 525.22,-44.4 483.72,-43.33 473.06,-39.69 431.83,-44.4 406.45,-47.3 379.09,-52.93 354.93,-58.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;354.4,-55.3 345.54,-61.11 356.09,-62.1 354.4,-55.3&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;478.52&quot; y=&quot;-47.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;register&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC2 --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;722.19,-154 601.79,-154 601.79,-102.8 722.19,-102.8 722.19,-154&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-139.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;User-Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-124.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(instance 2)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;661.99&quot; y=&quot;-110.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;register + heartbeat&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC2&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC2-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M601.33,-126.72C582.7,-125.97 562.09,-124.9 543.22,-123.4 461.92,-116.94 441.29,-114.64 361.58,-97.4 359.42,-96.93 357.23,-96.45 355.01,-95.95&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;355.86,-92.56 345.33,-93.72 354.29,-99.38 355.86,-92.56&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;478.52&quot; y=&quot;-124.76&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;register&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;106.02,-64.8 0,-64.8 0,-28 106.02,-28 106.02,-64.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;53.01&quot; y=&quot;-50&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Order-Service&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;53.01&quot; y=&quot;-35.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(discovery client)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;EUREKA --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;EUREKA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M106.24,-53.7C137.78,-58.11 178.37,-63.78 212.69,-68.58&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;212.18,-72.04 222.57,-69.96 213.15,-65.11 212.18,-72.04&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;165.15&quot; y=&quot;-70.14&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;discover instances&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CALL --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CALL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;339.62,-36.8 228.25,-36.8 228.25,0 339.62,0 339.62,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;283.93&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;REST call to&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;283.93&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;http://user-service&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;CALL --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;CALL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M106.24,-40.01C139.11,-35.99 181.81,-30.77 216.99,-26.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;217.13,-29.97 226.63,-25.29 216.28,-23.03 217.13,-29.97&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;SVC1 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;SVC1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M525.37,-72.95C531.36,-71.69 537.43,-70.48 543.22,-69.4 558.43,-66.57 574.82,-63.85 590.39,-61.43&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;590.7,-64.92 600.06,-59.95 589.64,-58 590.7,-64.92&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;563.5&quot; y=&quot;-72.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;route call&lt;/text&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;SVC2 --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;SVC2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M525.31,-94.76C545.07,-99.66 568.64,-105.5 590.54,-110.93&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;589.46,-114.27 600.01,-113.28 591.14,-107.47 589.46,-114.27&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;563.5&quot; y=&quot;-111.59&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;route call&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CALL&amp;#45;&amp;gt;LB --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CALL-&gt;LB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M339.86,-36.94C365.25,-45.51 395.38,-55.68 420.97,-64.31&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;419.6,-67.55 430.2,-67.43 421.84,-60.91 419.6,-67.55&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Eureka Server&lt;/strong&gt;: Central registry; each service registers its metadata (host, port, health URL)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@EnableEurekaClient&lt;/strong&gt;: Annotation to make a Spring Boot service a Eureka client&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Heartbeat mechanism&lt;/strong&gt;: Periodic renewal (30s); eviction after missed heartbeats (90s default)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Client-side load balancing&lt;/strong&gt;: Spring Cloud LoadBalancer selects instance; supports round-robin, weighted, custom strategies&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Self-preservation mode&lt;/strong&gt;: Eureka stops evicting instances during network partition — favors availability over consistency&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;OpenFeign&lt;/strong&gt;: Declarative HTTP client — &lt;code class=&quot;notranslate&quot;&gt;@FeignClient(&quot;user-service&quot;)&lt;/code&gt; interface with &lt;code class=&quot;notranslate&quot;&gt;@GetMapping(&quot;/api/users&quot;)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud&lt;/a&gt; — Service discovery is a core Spring Cloud feature&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Eureka client auto-configuration via Spring Boot&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-api-gateway&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-api-gateway&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud API Gateway&lt;/a&gt; — Gateway routes requests using service discovery&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — Service discovery is essential for microservice communication&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../dns&quot; class=&quot;internal alias&quot; data-slug=&quot;dns&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DNS&lt;/a&gt; — DNS resolves hostname → IP; service discovery resolves service name → dynamic IP list&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Eureka AP vs CP&lt;/strong&gt;: Eureka favors Availability over Consistency (AP in CAP theorem) — during network partitions, stale instances remain&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Slow startup&lt;/strong&gt;: First call after startup may fail because the client’s registry is not yet populated — use retries&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Zone affinity&lt;/strong&gt;: Eureka supports zones for regional deployment — clients prefer instances in the same zone&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Default port&lt;/strong&gt;: Eureka server runs on port 8761 by default — change via &lt;code class=&quot;notranslate&quot;&gt;server.port&lt;/code&gt; in configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stale cache&lt;/strong&gt;: Client caches the registry — use appropriate refresh intervals or manual eviction in failure scenarios&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-cloud</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-cloud" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-cloud.md" />
    <summary>The Problem Building cloud-native microservices requires solving distributed system challenges: service discovery (how do services find each other?), load balancing (which instance to call?), distributed configuration (how to manage config across services?), and fault tolerance (what happens when a ...</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="cloud" label="cloud" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Building cloud-native microservices requires solving distributed system challenges: service discovery (how do services find each other?), load balancing (which instance to call?), distributed configuration (how to manage config across services?), and fault tolerance (what happens when a service is down?).&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Cloud provides a suite of tools for building cloud-native microservices. It integrates with Netflix OSS (Eureka for service discovery, Ribbon for load balancing, Hystrix for circuit breaking), provides distributed configuration with Spring Cloud Config, API gateway with Spring Cloud Gateway, and distributed tracing with Sleuth/Zipkin.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Service discovery&lt;/strong&gt;: Spring Cloud Netflix Eureka — services register with Eureka server, clients discover via service name&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Load balancing&lt;/strong&gt;: Spring Cloud LoadBalancer (replaced Netflix Ribbon) — client-side load balancing across service instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;API Gateway&lt;/strong&gt;: Spring Cloud Gateway — routes requests to appropriate services, handles cross-cutting (auth, rate limiting)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distributed config&lt;/strong&gt;: Spring Cloud Config Server — external configuration stored in Git, served to all services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distributed tracing&lt;/strong&gt;: Spring Cloud Sleuth + Zipkin — trace IDs propagate across service calls, visualized in Zipkin dashboard&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fault tolerance&lt;/strong&gt;: Resilience4j (replaced Hystrix) — circuit breakers, retries, bulkheads, rate limiters&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_cloud Pages: 1 --&gt;
&lt;svg width=&quot;382pt&quot; height=&quot;350pt&quot; viewBox=&quot;0.00 0.00 382.00 350.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 346.2)&quot;&gt;
&lt;title&gt;spring_cloud&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-346.2 377.88,-346.2 377.88,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;223.53,-342.2 169.53,-342.2 169.53,-306.2 223.53,-306.2 223.53,-342.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-320.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GATEWAY&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;268.55,-269.2 124.5,-269.2 124.5,-232.4 268.55,-232.4 268.55,-269.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-254.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;API Gateway&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-240&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Spring Cloud Gateway)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;GATEWAY --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;GATEWAY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M196.53,-305.92C196.53,-298.45 196.53,-289.51 196.53,-281.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;200.03,-281.18 196.53,-271.18 193.03,-281.18 200.03,-281.18&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;LB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;281.9,-195.4 111.15,-195.4 111.15,-158.6 281.9,-158.6 281.9,-195.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Load Balancer&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Spring Cloud LoadBalancer)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GATEWAY&amp;#45;&amp;gt;LB --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GATEWAY-&gt;LB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M196.53,-232.05C196.53,-224.49 196.53,-215.46 196.53,-206.98&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;200.03,-207.06 196.53,-197.06 193.03,-207.06 200.03,-207.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DISCOVERY --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DISCOVERY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;239.2,-36.8 135.85,-36.8 135.85,0 239.2,0 239.2,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;187.53&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service Registry&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;187.53&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Eureka Server)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CONFIG --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONFIG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;113.21,-36.8 23.84,-36.8 23.84,0 113.21,0 113.21,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;68.53&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Config Server&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;68.53&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Git-backed)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;140.2,-121.6 62.85,-121.6 62.85,-84.8 140.2,-84.8 140.2,-121.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.53&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service A&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;101.53&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(registered)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1&amp;#45;&amp;gt;DISCOVERY --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC1-&gt;DISCOVERY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M100.25,-84.41C100.46,-74.77 102.28,-63.15 108.61,-54.8 113.24,-48.69 119.17,-43.61 125.68,-39.39&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;127.27,-42.51 134.25,-34.55 123.83,-36.42 127.27,-42.51&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.07&quot; y=&quot;-57.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;register / discover&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1&amp;#45;&amp;gt;CONFIG --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC1-&gt;CONFIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M62.45,-98.73C41.24,-94.62 16.71,-85.77 3.38,-66.8 -4.04,-56.23 2.36,-47.12 13.59,-39.79&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;15.09,-42.96 22.12,-35.04 11.69,-36.85 15.09,-42.96&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;28.95&quot; y=&quot;-57.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;fetch config&lt;/text&gt;
&lt;/g&gt;
&lt;!-- TRACING --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TRACING&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;373.88,-36.8 257.17,-36.8 257.17,0 373.88,0 373.88,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.53&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Distributed Tracing&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;315.53&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Sleuth + Zipkin)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC1&amp;#45;&amp;gt;TRACING --&gt;
&lt;g id=&quot;edge12&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC1-&gt;TRACING&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M140.28,-87.21C173.53,-74.34 221.87,-55.64 259.36,-41.13&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;260.15,-44.58 268.21,-37.71 257.62,-38.05 260.15,-44.58&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC2 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;332.2,-121.6 254.85,-121.6 254.85,-84.8 332.2,-84.8 332.2,-121.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;293.53&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service B&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;293.53&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(registered)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC2&amp;#45;&amp;gt;DISCOVERY --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC2-&gt;DISCOVERY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M271.8,-84.48C260.71,-75.5 246.97,-64.48 234.53,-54.8 230.01,-51.28 225.21,-47.61 220.48,-44.02&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;222.84,-41.41 212.75,-38.18 218.62,-47 222.84,-41.41&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC2&amp;#45;&amp;gt;CONFIG --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC2-&gt;CONFIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M259.19,-84.52C239.69,-74.91 214.62,-63.3 191.53,-54.8 163.39,-44.45 155.33,-45.11 126.53,-36.8 125.73,-36.57 124.93,-36.34 124.12,-36.11&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;125.49,-32.86 114.91,-33.41 123.53,-39.58 125.49,-32.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC2&amp;#45;&amp;gt;TRACING --&gt;
&lt;g id=&quot;edge13&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC2-&gt;TRACING&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M300.72,-84.38C302.79,-78.81 304.92,-72.61 306.53,-66.8 308.16,-60.9 309.59,-54.5 310.81,-48.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;314.24,-49.07 312.6,-38.61 307.35,-47.81 314.24,-49.07&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC3 --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SVC3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;235.2,-121.6 157.85,-121.6 157.85,-84.8 235.2,-84.8 235.2,-121.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Service C&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;196.53&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(registered)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SVC3&amp;#45;&amp;gt;DISCOVERY --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC3-&gt;DISCOVERY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M194.62,-84.64C193.48,-74.17 192.01,-60.62 190.7,-48.58&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;194.19,-48.29 189.63,-38.72 187.23,-49.04 194.19,-48.29&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC3&amp;#45;&amp;gt;CONFIG --&gt;
&lt;g id=&quot;edge11&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC3-&gt;CONFIG&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M157.56,-87.72C154.84,-86.73 152.14,-85.75 149.53,-84.8 126.92,-76.63 117.32,-81.78 98.53,-66.8 91.82,-61.46 86.18,-54.19 81.67,-46.95&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;84.92,-45.58 76.96,-38.59 78.82,-49.02 84.92,-45.58&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SVC3&amp;#45;&amp;gt;TRACING --&gt;
&lt;g id=&quot;edge14&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SVC3-&gt;TRACING&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M228.51,-84.48C237.72,-79.07 247.67,-72.92 256.53,-66.8 266.41,-59.96 276.77,-51.96 286,-44.49&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;288.11,-47.28 293.62,-38.23 283.67,-41.88 288.11,-47.28&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;SVC1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;SVC1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M173.04,-158.25C161.28,-149.36 146.85,-138.46 134.05,-128.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;136.36,-126.14 126.28,-122.91 132.14,-131.73 136.36,-126.14&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;SVC2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;SVC2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M220.5,-158.25C232.51,-149.36 247.24,-138.46 260.32,-128.78&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;262.32,-131.66 268.27,-122.89 258.15,-126.03 262.32,-131.66&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- LB&amp;#45;&amp;gt;SVC3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;LB-&gt;SVC3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M196.53,-158.25C196.53,-150.69 196.53,-141.66 196.53,-133.18&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;200.03,-133.26 196.53,-123.26 193.03,-133.26 200.03,-133.26&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Service discovery&lt;/strong&gt;: Eureka server for service registration and discovery; Spring Cloud LoadBalancer for client-side load balancing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;API Gateway&lt;/strong&gt;: Route requests, add headers, rate-limiting, authentication, circuit breaking at edge&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuration management&lt;/strong&gt;: Externalized, version-controlled configuration via Spring Cloud Config (Git backend)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circuit breakers&lt;/strong&gt;: Resilience4j for fault tolerance — prevents cascading failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Distributed tracing&lt;/strong&gt;: Sleuth adds trace/span IDs; Zipkin visualizes request flows across services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Cloud platform support&lt;/strong&gt;: AWS (EC2, S3, SQS), GCP, Azure integrations via Spring Cloud for each provider&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Spring Cloud builds on Spring Boot’s auto-configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Spring Cloud uses Spring’s DI and configuration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-service-discovery&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-service-discovery&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud Service Discovery&lt;/a&gt; — Eureka and LoadBalancer enable service-to-service calls&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-cloud-api-gateway&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-cloud-api-gateway&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Cloud API Gateway&lt;/a&gt; — Gateway is the entry point for all microservices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../java-microservices&quot; class=&quot;internal alias&quot; data-slug=&quot;java-microservices&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Microservices&lt;/a&gt; — Spring Cloud provides the infrastructure for microservices&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../j2ee-specification&quot; class=&quot;internal alias&quot; data-slug=&quot;j2ee-specification&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;J2EE Specification&lt;/a&gt; — J2EE is monolithic; Spring Cloud is cloud-native microservices&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Eureka self-preservation&lt;/strong&gt;: In network partitions, Eureka keeps its registrations (AP over CP) — stale entries during real failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Config server SPOF&lt;/strong&gt;: Config server is a single point of failure — make it highly available or use native cloud config services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gateway latency&lt;/strong&gt;: Every request goes through the gateway, adding latency — avoid putting heavy logic in gateway filters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bootstrap context&lt;/strong&gt;: Spring Cloud uses &lt;code class=&quot;notranslate&quot;&gt;bootstrap.yml&lt;/code&gt; (loaded before application.yml) for config server location — easy to misconfigure&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Version compatibility&lt;/strong&gt;: Spring Cloud releases are coordinated (2020.0.x, 2021.0.x, etc.) — Spring Boot version must match the cloud release train&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-controller</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-controller" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-controller.md" />
    <summary>The Problem Web application logic needs to respond to specific URL patterns, extract parameters from requests, and return data or views to the client.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Web application logic needs to respond to specific URL patterns, extract parameters from requests, and return data or views to the client. Without a structured approach, each page would manually parse URLs, manage HTTP methods, and construct responses — duplicating effort across handlers.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Controllers are &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt;-annotated classes whose methods handle specific URL patterns and HTTP methods, defined via &lt;code class=&quot;notranslate&quot;&gt;@RequestMapping&lt;/code&gt; and its shortcut annotations (&lt;code class=&quot;notranslate&quot;&gt;@GetMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostMapping&lt;/code&gt;, etc.). &lt;code class=&quot;notranslate&quot;&gt;@RestController&lt;/code&gt; combines &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt; with &lt;code class=&quot;notranslate&quot;&gt;@ResponseBody&lt;/code&gt; for REST APIs, automatically serializing return values to JSON or XML.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@RequestMapping&lt;/strong&gt;: Maps HTTP method + URL path to a controller method — e.g., &lt;code class=&quot;notranslate&quot;&gt;@GetMapping(&quot;/users/{id}&quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Method parameters&lt;/strong&gt;: Automatically bound from request: &lt;code class=&quot;notranslate&quot;&gt;@RequestParam&lt;/code&gt; (query params), &lt;code class=&quot;notranslate&quot;&gt;@PathVariable&lt;/code&gt; (URL segments), &lt;code class=&quot;notranslate&quot;&gt;@RequestBody&lt;/code&gt; (JSON body), &lt;code class=&quot;notranslate&quot;&gt;@ModelAttribute&lt;/code&gt; (form data)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Return types&lt;/strong&gt;: String (view name), ModelAndView, &lt;code class=&quot;notranslate&quot;&gt;@ResponseBody&lt;/code&gt; (JSON/XML), ResponseEntity (full control)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@RestController&lt;/strong&gt;: All methods default to &lt;code class=&quot;notranslate&quot;&gt;@ResponseBody&lt;/code&gt;; no view resolution — returns data directly&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Controller vs @RestController&lt;/strong&gt;: @Controller returns view names; @RestController returns data (JSON/XML)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_controller Pages: 1 --&gt;
&lt;svg width=&quot;808pt&quot; height=&quot;236pt&quot; viewBox=&quot;0.00 0.00 808.00 236.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 231.8)&quot;&gt;
&lt;title&gt;spring_controller&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-231.8 804.43,-231.8 804.43,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- REQ --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REQ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;123.73,-144.8 0,-144.8 0,-108 123.73,-108 123.73,-144.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.87&quot; y=&quot;-130&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Request&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;61.87&quot; y=&quot;-115.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;GET /users?page=1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;270.44,-144.4 159.73,-144.4 159.73,-108.4 270.44,-108.4 270.44,-144.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;215.08&quot; y=&quot;-122.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DispatcherServlet&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REQ&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REQ-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M123.94,-126.4C131.96,-126.4 140.21,-126.4 148.3,-126.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;148.1,-129.9 158.1,-126.4 148.1,-122.9 148.1,-129.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;485.51,-144.4 306.44,-144.4 306.44,-108.4 485.51,-108.4 485.51,-144.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;395.97&quot; y=&quot;-122.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Controller / @RestController&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;CTRL --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;CTRL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M270.73,-126.4C278.43,-126.4 286.54,-126.4 294.77,-126.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;294.53,-129.9 304.53,-126.4 294.53,-122.9 294.53,-129.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- P1 --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P1&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;629.73,-227.8 521.51,-227.8 521.51,-191 629.73,-191 629.73,-227.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-213&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@RequestParam&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-198.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;page=1&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;P1 --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;P1&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M436.4,-144.82C462.23,-156.89 496.24,-172.78 524.06,-185.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;522.47,-188.9 533.01,-189.96 525.44,-182.56 522.47,-188.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- P2 --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P2&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;624.07,-172.8 527.18,-172.8 527.18,-136 624.07,-136 624.07,-172.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-158&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@PathVariable&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-143.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;/user/{id}&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;P2 --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;P2&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M485.8,-140.4C496.02,-142.01 506.25,-143.62 515.93,-145.15&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;515.1,-148.56 525.52,-146.66 516.19,-141.65 515.1,-148.56&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- P3 --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;P3&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;625.74,-117.8 525.51,-117.8 525.51,-81 625.74,-81 625.74,-117.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-103&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@RequestBody&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-88.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JSON body&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;P3 --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;P3&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M485.8,-112.9C495.31,-111.45 504.83,-110.01 513.91,-108.63&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;514.28,-112.11 523.64,-107.15 513.23,-105.19 514.28,-112.11&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;610.64,-63.4 540.61,-63.4 540.61,-27.4 610.64,-27.4 610.64,-63.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;575.62&quot; y=&quot;-41.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Response&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M437.29,-108.02C464.79,-95.48 501.25,-78.86 529.69,-65.89&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;531.14,-69.08 538.78,-61.74 528.23,-62.71 531.14,-69.08&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- VIEW --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;VIEW&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;800.43,-91.8 665.73,-91.8 665.73,-55 800.43,-55 800.43,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.08&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;View (JSP/Thymeleaf)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.08&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(if @Controller)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESP&amp;#45;&amp;gt;VIEW --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RESP-&gt;VIEW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M611.13,-51.61C624.01,-53.93 639.22,-56.67 654.42,-59.41&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;653.51,-62.8 663.97,-61.13 654.75,-55.91 653.51,-62.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JSON --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JSON&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;794.18,-36.8 671.98,-36.8 671.98,0 794.18,0 794.18,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.08&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JSON/XML&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.08&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(if @RestController)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESP&amp;#45;&amp;gt;JSON --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RESP-&gt;JSON&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M611.13,-39.41C625.73,-36.87 643.31,-33.82 660.5,-30.83&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;660.95,-34.31 670.21,-29.15 659.75,-27.41 660.95,-34.31&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@RequestMapping shortcuts&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@GetMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PutMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@DeleteMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PatchMapping&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@PathVariable&lt;/strong&gt;: Binds URL template variables — &lt;code class=&quot;notranslate&quot;&gt;@GetMapping(&quot;/users/{id}&quot;)&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;(@PathVariable Long id)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@RequestParam&lt;/strong&gt;: Binds query parameters with optional default values and required flag&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@RequestBody&lt;/strong&gt;: Deserializes request body (JSON/XML) to Java object using HttpMessageConverter&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ResponseBody&lt;/strong&gt;: Serializes return value directly to HTTP response body&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ResponseStatus&lt;/strong&gt;: Sets HTTP status code on successful method execution&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Controllers are the handler components in Spring MVC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../dispatcher-servlet&quot; class=&quot;internal alias&quot; data-slug=&quot;dispatcher-servlet&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DispatcherServlet&lt;/a&gt; — DispatcherServlet invokes controller methods&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-form-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-form-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Form Handling&lt;/a&gt; — @ModelAttribute binds form data to model objects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc-exception-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc-exception-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC Exception Handling&lt;/a&gt; — @ExceptionHandler in controllers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../servlets&quot; class=&quot;internal alias&quot; data-slug=&quot;servlets&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Servlets&lt;/a&gt; — Servlets extend HttpServlet; Spring Controllers are POJOs with annotations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@RequestParam required=true by default&lt;/strong&gt;: Missing required param returns 400 — use &lt;code class=&quot;notranslate&quot;&gt;required=false&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;defaultValue&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@PathVariable vs @RequestParam&lt;/strong&gt;: Path variables identify resources; request params filter/ paginate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ResponseBody + String&lt;/strong&gt;: Returns the string itself, not a view name — common confusion with @Controller&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Method-level vs class-level @RequestMapping&lt;/strong&gt;: Class-level is the prefix; method-level defines the specific endpoint&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-data-jpa</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-data-jpa" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-data-jpa.md" />
    <summary>The Problem Implementing data access layers requires writing repetitive DAO (Data Access Object) code: creating queries, managing EntityManager, handling transactions, mapping results.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Implementing data access layers requires writing repetitive DAO (Data Access Object) code: creating queries, managing EntityManager, handling transactions, mapping results. Even with Hibernate, developers still write CRUD methods for every entity — findAll, findById, save, delete, plus custom query methods.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Data JPA is a data access framework that eliminates boilerplate repository code. By extending &lt;code class=&quot;notranslate&quot;&gt;JpaRepository&lt;/code&gt; (or &lt;code class=&quot;notranslate&quot;&gt;CrudRepository&lt;/code&gt;), interfaces automatically inherit CRUD methods without implementation. Custom queries are derived from method names (e.g., &lt;code class=&quot;notranslate&quot;&gt;findByLastName(String name)&lt;/code&gt;) or defined via &lt;code class=&quot;notranslate&quot;&gt;@Query&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Repository interface&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;public interface UserRepository extends JpaRepository&amp;#x3C;User, Long&gt;&lt;/code&gt; — no implementation needed&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inherited methods&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;findAll()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;findById()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;save()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;delete()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;count()&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;existsById()&lt;/code&gt; — all auto-implemented&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Derived query methods&lt;/strong&gt;: Method names like &lt;code class=&quot;notranslate&quot;&gt;findByEmailAndActive(String email, boolean active)&lt;/code&gt; — Spring Data parses the name and generates JPQL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Query&lt;/strong&gt;: Custom JPQL or native SQL queries for complex operations: &lt;code class=&quot;notranslate&quot;&gt;@Query(&quot;SELECT u FROM User u WHERE u.email = :email&quot;)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pagination&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Pageable&lt;/code&gt; parameter returns &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;T&gt;&lt;/code&gt; with total count, sorting, and pagination metadata&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sorting&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Sort.by(&quot;lastName&quot;).ascending()&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;findAll(Sort.by(&quot;lastName&quot;))&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_data_jpa Pages: 1 --&gt;
&lt;svg width=&quot;362pt&quot; height=&quot;350pt&quot; viewBox=&quot;0.00 0.00 362.00 350.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 345.6)&quot;&gt;
&lt;title&gt;spring_data_jpa&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-345.6 357.71,-345.6 357.71,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;216.38,-341.6 141.67,-341.6 141.67,-304.8 216.38,-304.8 216.38,-341.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-326.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-312.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Caller)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REPO&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;252.05,-268.8 105.99,-268.8 105.99,-232 252.05,-232 252.05,-268.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-254&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;UserRepository&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-239.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(extends JpaRepository)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;REPO --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;REPO&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.02,-304.33C179.02,-297.07 179.02,-288.48 179.02,-280.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;182.52,-280.53 179.02,-270.53 175.52,-280.53 182.52,-280.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CRUD --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CRUD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;102.04,-196 0,-196 0,-144.8 102.04,-144.8 102.04,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.02&quot; y=&quot;-181.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Inherited CRUD&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.02&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;findAll, findById,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;51.02&quot; y=&quot;-152.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;save, delete&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;CRUD --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;CRUD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M149.66,-231.51C135.34,-222.78 117.72,-212.04 101.35,-202.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;103.54,-199.31 93.18,-197.09 99.9,-205.28 103.54,-199.31&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- QUERY --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;QUERY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;238.37,-188.8 119.67,-188.8 119.67,-152 238.37,-152 238.37,-188.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-174&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Derived Queries&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-159.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;findByEmail(String)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;QUERY --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;QUERY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.02,-231.7C179.02,-222.49 179.02,-211 179.02,-200.52&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;182.52,-200.81 179.02,-190.81 175.52,-200.81 182.52,-200.81&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JPQL --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JPQL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;353.71,-188.8 256.34,-188.8 256.34,-152 353.71,-152 353.71,-188.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;305.02&quot; y=&quot;-174&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Query JPQL&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;305.02&quot; y=&quot;-159.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;custom queries&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REPO&amp;#45;&amp;gt;JPQL --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REPO-&gt;JPQL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M207.93,-231.51C225.3,-220.75 247.61,-206.94 266.47,-195.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;268.3,-198.25 274.96,-190.01 264.62,-192.3 268.3,-198.25&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PROVIDER --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROVIDER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;222.04,-108.8 136.01,-108.8 136.01,-72 222.04,-72 222.04,-108.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-94&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JPA Provider&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-79.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Hibernate)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CRUD&amp;#45;&amp;gt;PROVIDER --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CRUD-&gt;PROVIDER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M91.87,-144.51C107.36,-135.07 124.93,-124.36 140.22,-115.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;141.89,-118.13 148.6,-109.94 138.24,-112.15 141.89,-118.13&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- QUERY&amp;#45;&amp;gt;PROVIDER --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;QUERY-&gt;PROVIDER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.02,-151.7C179.02,-142.49 179.02,-131 179.02,-120.52&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;182.52,-120.81 179.02,-110.81 175.52,-120.81 182.52,-120.81&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JPQL&amp;#45;&amp;gt;PROVIDER --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JPQL-&gt;PROVIDER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M276.12,-151.51C258.75,-140.75 236.43,-126.94 217.58,-115.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;219.43,-112.3 209.08,-110.01 215.74,-118.25 219.43,-112.3&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;212.71,-36 145.34,-36 145.34,0 212.71,0 212.71,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;179.02&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROVIDER&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROVIDER-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M179.02,-71.64C179.02,-64.3 179.02,-55.61 179.02,-47.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;182.52,-47.54 179.02,-37.54 175.52,-47.54 182.52,-47.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Interface-based&lt;/strong&gt;: No implementation to write — Spring Data generates the proxy at runtime&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Derived queries&lt;/strong&gt;: Parse method naming conventions: &lt;code class=&quot;notranslate&quot;&gt;findBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;readBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;countBy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;deleteBy&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Query methods&lt;/strong&gt;: Support AND, OR, Between, LessThan, GreaterThan, Like, In, IgnoreCase, OrderBy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pagination&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Pageable&lt;/code&gt; parameter → &lt;code class=&quot;notranslate&quot;&gt;Page&amp;#x3C;T&gt;&lt;/code&gt; result with total elements, total pages, sorting&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sorting&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;Sort.by()&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;Pageable&lt;/code&gt; with Sort; also &lt;code class=&quot;notranslate&quot;&gt;findAll(Sort.by(&quot;field&quot;))&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom queries&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Query(&quot;...&quot;)&lt;/code&gt; for JPQL; &lt;code class=&quot;notranslate&quot;&gt;@Query(value = &quot;...&quot;, nativeQuery = true)&lt;/code&gt; for native SQL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modifying queries&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Modifying&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@Query&lt;/code&gt; for UPDATE/DELETE operations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Spring Boot auto-configures DataSource, JPA, and repository scanning&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-jdbc&quot; class=&quot;internal alias&quot; data-slug=&quot;java-jdbc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JDBC&lt;/a&gt; — Spring Data JPA ultimately uses JDBC for database access&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — Hibernate is the default JPA provider for Spring Data JPA&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-repository&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-repository&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JpaRepository&lt;/a&gt; — The core repository interface in Spring Data JPA&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-query-methods&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-query-methods&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Query Methods&lt;/a&gt; — Derived query method naming conventions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jpa-pagination-sorting&quot; class=&quot;internal alias&quot; data-slug=&quot;jpa-pagination-sorting&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JPA Pagination and Sorting&lt;/a&gt; — Paging and sorting with Spring Data JPA&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Derived method explosion&lt;/strong&gt;: Complex queries with many conditions produce unwieldy method names — use &lt;code class=&quot;notranslate&quot;&gt;@Query&lt;/code&gt; instead&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;N+1 with findAll&lt;/strong&gt;: Default &lt;code class=&quot;notranslate&quot;&gt;findAll&lt;/code&gt; fetches associations lazily — consider &lt;code class=&quot;notranslate&quot;&gt;@EntityGraph&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;JOIN FETCH&lt;/code&gt; in &lt;code class=&quot;notranslate&quot;&gt;@Query&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transaction boundaries&lt;/strong&gt;: Repository methods are transactional by default, but service-layer transactions should wrap multiple repo calls&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proxy limitation&lt;/strong&gt;: Repository proxies can’t intercept internal method calls (method calls within the same class bypass the proxy)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-form-handling</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-form-handling" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-form-handling.md" />
    <summary>The Problem HTML forms submit data that must be extracted, validated, bound to objects, and re-displayed with error messages on failure.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;HTML forms submit data that must be extracted, validated, bound to objects, and re-displayed with error messages on failure. Manual form handling requires tedious request parameter extraction, field-by-field validation, and error tracking — all duplicated across every form in the application.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring MVC provides comprehensive form handling: &lt;code class=&quot;notranslate&quot;&gt;@ModelAttribute&lt;/code&gt; binds form fields to Java objects, &lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; triggers Bean Validation annotations, and &lt;code class=&quot;notranslate&quot;&gt;BindingResult&lt;/code&gt; captures validation errors for display in the view. Spring form tags (&lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:form&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:input&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:errors&gt;&lt;/code&gt;) integrate with the model for seamless two-way binding.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Form backing object&lt;/strong&gt;: A Java bean (POJO) holds form data; added to model via &lt;code class=&quot;notranslate&quot;&gt;@ModelAttribute&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GET request&lt;/strong&gt;: Controller adds empty/ pre-populated form object to model, returns form view&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Form submission&lt;/strong&gt;: POST request with form fields → Spring binds fields to &lt;code class=&quot;notranslate&quot;&gt;@ModelAttribute&lt;/code&gt; parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; on the parameter triggers annotation validation; errors go to &lt;code class=&quot;notranslate&quot;&gt;BindingResult&lt;/code&gt; (must be immediately after the validated parameter)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error handling&lt;/strong&gt;: If &lt;code class=&quot;notranslate&quot;&gt;BindingResult.hasErrors()&lt;/code&gt;, return to form view — errors display via &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:errors&gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Success&lt;/strong&gt;: If no errors, process data (save to DB) and redirect (POST-Redirect-GET pattern)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: form_handling Pages: 1 --&gt;
&lt;svg width=&quot;907pt&quot; height=&quot;106pt&quot; viewBox=&quot;0.00 0.00 907.00 106.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 101.8)&quot;&gt;
&lt;title&gt;form_handling&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-101.8 902.96,-101.8 902.96,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- GET --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;GET&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;119.36,-45.8 0,-45.8 0,-9 119.36,-9 119.36,-45.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.68&quot; y=&quot;-31&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;GET /form&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;59.68&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(empty form object)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FORM --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FORM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;280.38,-45.8 156.36,-45.8 156.36,-9 280.38,-9 280.38,-45.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;218.37&quot; y=&quot;-31&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Form View&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;218.37&quot; y=&quot;-16.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(JSP with form tags)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- GET&amp;#45;&amp;gt;FORM --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;GET-&gt;FORM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M119.47,-27.4C127.65,-27.4 136.13,-27.4 144.53,-27.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;144.38,-30.9 154.38,-27.4 144.38,-23.9 144.38,-30.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- POST --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;POST&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;475.77,-75.8 373.07,-75.8 373.07,-39 475.77,-39 475.77,-75.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;424.42&quot; y=&quot;-61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;POST /form&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;424.42&quot; y=&quot;-46.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(submitted data)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FORM&amp;#45;&amp;gt;POST --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;FORM-&gt;POST&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M280.87,-36.44C306.42,-40.2 336.03,-44.55 361.62,-48.31&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;360.79,-51.73 371.19,-49.72 361.8,-44.8 360.79,-51.73&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;326.73&quot; y=&quot;-49.84&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;user submits&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BIND --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BIND&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;618.33,-75.8 512.77,-75.8 512.77,-39 618.33,-39 618.33,-75.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;565.55&quot; y=&quot;-61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ModelAttribute&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;565.55&quot; y=&quot;-46.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;+ @Valid&lt;/text&gt;
&lt;/g&gt;
&lt;!-- POST&amp;#45;&amp;gt;BIND --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;POST-&gt;BIND&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M476.04,-57.4C484.16,-57.4 492.66,-57.4 501.03,-57.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;500.82,-60.9 510.82,-57.4 500.82,-53.9 500.82,-60.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ERR --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ERR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;745.37,-75.8 655.33,-75.8 655.33,-39 745.37,-39 745.37,-75.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;700.35&quot; y=&quot;-61&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;BindingResult&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;700.35&quot; y=&quot;-46.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;hasErrors?&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BIND&amp;#45;&amp;gt;ERR --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BIND-&gt;ERR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M618.66,-57.4C626.86,-57.4 635.36,-57.4 643.64,-57.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;643.62,-60.9 653.62,-57.4 643.62,-53.9 643.62,-60.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- OK --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;OK&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;890.3,-97.8 805.59,-97.8 805.59,-61 890.3,-61 890.3,-97.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;847.95&quot; y=&quot;-83&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;process data&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;847.95&quot; y=&quot;-68.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;redirect&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERR&amp;#45;&amp;gt;OK --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ERR-&gt;OK&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M745.83,-64.12C761.03,-66.42 778.2,-69.01 794.01,-71.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;793.32,-74.84 803.73,-72.87 794.37,-67.92 793.32,-74.84&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;771.15&quot; y=&quot;-72.06&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;no&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERROR --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ERROR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;898.96,-36.8 796.94,-36.8 796.94,0 898.96,0 898.96,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;847.95&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;return form view&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;847.95&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;with errors&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERR&amp;#45;&amp;gt;ERROR --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ERR-&gt;ERROR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M745.83,-45.49C758.37,-42.13 772.24,-38.41 785.59,-34.84&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;786.42,-38.24 795.17,-32.27 784.61,-31.47 786.42,-38.24&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;771.15&quot; y=&quot;-43.24&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;yes&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERROR&amp;#45;&amp;gt;FORM --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ERROR-&gt;FORM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M796.44,-14.78C768.44,-13.07 732.98,-11.4 701.35,-11.4 423.42,-11.4 423.42,-11.4 423.42,-11.4 379.6,-11.4 330.64,-15.11 291.67,-18.96&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;291.54,-15.46 281.94,-19.95 292.24,-22.42 291.54,-15.46&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@ModelAttribute&lt;/strong&gt;: Binds form fields to Java object fields by name match&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@Valid / @Validated&lt;/strong&gt;: Triggers Bean Validation (JSR-380) annotations like &lt;code class=&quot;notranslate&quot;&gt;@NotBlank&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Email&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Size&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BindingResult&lt;/strong&gt;: Must immediately follow @Valid parameter; holds field and global errors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Spring form tags&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:form&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:input&gt;&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;form:errors&gt;&lt;/code&gt; — automatically populate and display errors&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;POST-Redirect-GET&lt;/strong&gt;: Prevents duplicate form submission on refresh by redirecting after successful POST&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Type conversion&lt;/strong&gt;: Automatic conversion from String (form field) to int, long, date, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Form handling is part of Spring MVC’s web functionality&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — Controller methods handle form GET and POST&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc-exception-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc-exception-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC Exception Handling&lt;/a&gt; — Validation errors are distinct from exceptions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-try-catch-finally&quot; class=&quot;internal alias&quot; data-slug=&quot;java-try-catch-finally&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Try-Catch-Finally&lt;/a&gt; — BindingResult tracks validation errors similarly to structured error collection&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;BindingResult position&lt;/strong&gt;: Must immediately follow the @Valid parameter — any fields between them cause binding failure&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Errors on GET&lt;/strong&gt;: First GET request has no BindingResult — use separate method or check if it’s a rebind&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Nested properties&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; on nested objects requires cascading validation (&lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; on the nested field)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conversion errors&lt;/strong&gt;: Type mismatch (e.g., “abc” for int field) goes to BindingResult as a FieldError&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Custom validators&lt;/strong&gt;: Implement &lt;code class=&quot;notranslate&quot;&gt;Validator&lt;/code&gt; interface and register; or use &lt;code class=&quot;notranslate&quot;&gt;@Pattern&lt;/code&gt; for simple regex validation&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-framework</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-framework" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-framework.md" />
    <summary>The Problem Enterprise Java development requires handling cross-cutting concerns (transactions, security, logging) alongside business logic.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Enterprise Java development requires handling cross-cutting concerns (transactions, security, logging) alongside business logic. Without a framework, these concerns get scattered across the codebase (cross-cutting) and tangled with business code, making applications hard to develop, test, and maintain.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring is a lightweight, modular Java application framework centered on Inversion of Control (IoC) and Dependency Injection (DI). It provides infrastructure for managing objects (beans), wiring dependencies, and integrating with enterprise services (transactions, persistence, messaging, web) through a consistent programming model.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Bean container&lt;/strong&gt;: Spring’s IoC container (ApplicationContext) manages object creation, wiring, and lifecycle&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuration metadata&lt;/strong&gt;: Beans are defined via XML, annotations, or Java config (&lt;code class=&quot;notranslate&quot;&gt;@Configuration&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dependency Injection&lt;/strong&gt;: The container injects dependencies into beans at construction time, eliminating &lt;code class=&quot;notranslate&quot;&gt;new&lt;/code&gt; calls&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Aspect-Oriented Programming&lt;/strong&gt;: Spring AOP weaves cross-cutting concerns (transactions, security) into beans without modifying business code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modular architecture&lt;/strong&gt;: Spring is organized into modules: Core, MVC, Data, Security, Cloud, Boot — use what you need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_framework Pages: 1 --&gt;
&lt;svg width=&quot;626pt&quot; height=&quot;277pt&quot; viewBox=&quot;0.00 0.00 626.00 277.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 272.8)&quot;&gt;
&lt;title&gt;spring_framework&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-272.8 622.03,-272.8 622.03,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;443.71,-268.8 330.98,-268.8 330.98,-232.8 443.71,-232.8 443.71,-268.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;387.34&quot; y=&quot;-247.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Application&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CORE --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CORE&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;403.36,-196.8 283.33,-196.8 283.33,-160 403.36,-160 403.36,-196.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;343.34&quot; y=&quot;-182&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Core&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;343.34&quot; y=&quot;-167.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(IoC / DI Container)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;CORE --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;CORE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M376.47,-232.4C371.64,-224.67 365.84,-215.39 360.45,-206.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;363.47,-205 355.2,-198.37 357.53,-208.71 363.47,-205&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MODULES --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MODULES&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;357.03,-116.4 257.65,-116.4 257.65,-80.4 357.03,-80.4 357.03,-116.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;307.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Modules&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CORE&amp;#45;&amp;gt;MODULES --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CORE-&gt;MODULES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M335.17,-159.7C330.72,-150.06 325.12,-137.91 320.11,-127.05&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;323.36,-125.75 315.99,-118.13 317,-128.68 323.36,-125.75&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEANS --&gt;
&lt;g id=&quot;node10&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEANS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;487.36,-124 375.32,-124 375.32,-72.8 487.36,-72.8 487.36,-124&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;431.34&quot; y=&quot;-109.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Beans&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;431.34&quot; y=&quot;-94.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(POJOs managed&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;431.34&quot; y=&quot;-80.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;by container)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CORE&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CORE-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M363.31,-159.7C372.6,-151.47 383.94,-141.42 394.68,-131.9&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;396.82,-134.68 401.98,-125.43 392.18,-129.44 396.82,-134.68&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- MVC --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MVC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;80.69,-36.8 0,-36.8 0,0 80.69,0 80.69,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;40.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring MVC&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;40.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Web)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;MVC --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;MVC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M257.53,-84.44C215.79,-73.37 154.43,-56.59 91.81,-37.16&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;92.97,-33.86 82.38,-34.21 90.88,-40.54 92.97,-33.86&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DATA --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DATA&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;185.69,-36.8 99,-36.8 99,0 185.69,0 185.69,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Data&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;142.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Persistence)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;DATA --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;DATA&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M270.72,-80.09C247.03,-68.89 215.92,-54.18 190.27,-42.05&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;191.91,-38.96 181.37,-37.85 188.92,-45.29 191.91,-38.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- SEC --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SEC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;301.03,-36.8 203.66,-36.8 203.66,0 301.03,0 301.03,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Security&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Auth)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;SEC --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;SEC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M295.14,-80.09C288.19,-70.23 279.32,-57.66 271.47,-46.52&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;274.39,-44.6 265.77,-38.44 268.67,-48.63 274.39,-44.6&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BOOT --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BOOT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;406.02,-36.8 318.66,-36.8 318.66,0 406.02,0 406.02,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;362.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Boot&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;362.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Auto-Config)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;BOOT --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;BOOT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M319.55,-80.09C326.5,-70.23 335.36,-57.66 343.22,-46.52&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;346.02,-48.63 348.92,-38.44 340.29,-44.6 346.02,-48.63&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CLOUD --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLOUD&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;521.01,-36.8 423.68,-36.8 423.68,0 521.01,0 521.01,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;472.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Cloud&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;472.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Microservices)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;CLOUD --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;CLOUD&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M343.96,-80.09C367.66,-68.89 398.77,-54.18 424.42,-42.05&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;425.77,-45.29 433.31,-37.85 422.78,-38.96 425.77,-45.29&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AOP --&gt;
&lt;g id=&quot;node9&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AOP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;618.03,-36.8 538.66,-36.8 538.66,0 618.03,0 618.03,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;578.34&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring AOP&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;578.34&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Aspects)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODULES&amp;#45;&amp;gt;AOP --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;MODULES-&gt;AOP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M346.33,-80C352.94,-77.38 359.78,-74.87 366.34,-72.8 434.18,-51.4 456.57,-56.95 527.56,-37.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;528.28,-40.83 536.95,-34.74 526.37,-34.1 528.28,-40.83&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEANS&amp;#45;&amp;gt;APP --&gt;
&lt;g id=&quot;edge10&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BEANS-&gt;APP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M428.23,-124.25C425.33,-144.19 420.23,-172.73 412.34,-196.8 409.56,-205.31 405.73,-214.23 401.91,-222.27&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;398.78,-220.71 397.47,-231.22 405.05,-223.82 398.78,-220.71&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Lightweight&lt;/strong&gt;: No application server required; runs in any JVM with a servlet container (Tomcat)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;POJO-based&lt;/strong&gt;: Business objects are plain Java objects with no Spring coupling (except annotations)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Non-invasive&lt;/strong&gt;: Application code doesn’t extend Spring classes or implement Spring interfaces&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Modular&lt;/strong&gt;: Choose only the modules your application needs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testable&lt;/strong&gt;: DI makes unit testing trivial — mock dependencies can be injected in tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration&lt;/strong&gt;: First-class support for Hibernate, JPA, JDBC, JMS, JTA, JNDI&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — Core of Spring, manages beans and DI&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Web framework built on Spring Core&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Auto-configuration on top of Spring Framework&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — Security built on Spring AOP and DI&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../component-architecture-soa&quot; class=&quot;internal alias&quot; data-slug=&quot;component-architecture-soa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Component Architecture &amp;#x26; SOA&lt;/a&gt; — Both Spring and EJB address component-based enterprise development&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../session-bean&quot; class=&quot;internal alias&quot; data-slug=&quot;session-bean&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Session Bean&lt;/a&gt; — Spring beans are lighter, no EJB container needed&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Configuration hell&lt;/strong&gt;: Too many XML/annotation configurations can become as hard to manage as the problems Spring solves&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Circular dependencies&lt;/strong&gt;: Bean A depends on B which depends on A causes container startup failure; use setter injection or @Lazy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Proxy limitations&lt;/strong&gt;: Spring AOP (JDK dynamic proxies) only intercepts public method calls on Spring-managed beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Over-autowiring&lt;/strong&gt;: Auto-wiring everything makes dependency graphs implicit and hard to trace&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-ioc-container</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-ioc-container" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-ioc-container.md" />
    <summary>The Problem In traditional Java applications, each object creates its own dependencies using new — tightly coupling classes to their collaborators.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;In traditional Java applications, each object creates its own dependencies using &lt;code class=&quot;notranslate&quot;&gt;new&lt;/code&gt; — tightly coupling classes to their collaborators. This coupling makes it hard to swap implementations, test in isolation, or change application behavior without editing source code.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;The Spring IoC (Inversion of Control) Container is responsible for instantiating, configuring, and managing the lifecycle of Java objects (beans). Instead of objects creating their dependencies, the container creates everything and injects dependencies into objects. Two container types exist: BeanFactory (basic) and ApplicationContext (feature-rich).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;BeanFactory&lt;/strong&gt;: The simplest container providing basic DI support. Lazy-initializes beans by default. Suitable for resource-constrained environments (mobile, applets)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ApplicationContext&lt;/strong&gt;: Extends BeanFactory with enterprise features: event publishing, message i18n, AOP integration, declarative startup, and web application support. Eager-initializes singletons by default. Used in virtually all Spring applications&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuration&lt;/strong&gt;: Beans defined via XML (&lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;bean&gt;&lt;/code&gt;), annotations (&lt;code class=&quot;notranslate&quot;&gt;@Component&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@Service&lt;/code&gt;), or Java config (&lt;code class=&quot;notranslate&quot;&gt;@Bean&lt;/code&gt; in &lt;code class=&quot;notranslate&quot;&gt;@Configuration&lt;/code&gt; class)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Instantiation&lt;/strong&gt;: Container reads configuration, validates bean definitions, resolves dependencies, and creates bean instances&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Injection&lt;/strong&gt;: Dependencies injected via constructor, setter, or field (using &lt;code class=&quot;notranslate&quot;&gt;@Autowired&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: ioc_container Pages: 1 --&gt;
&lt;svg width=&quot;234pt&quot; height=&quot;303pt&quot; viewBox=&quot;0.00 0.00 234.00 303.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 298.6)&quot;&gt;
&lt;title&gt;ioc_container&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-298.6 229.71,-298.6 229.71,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CFG --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CFG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;180.72,-294.6 23.32,-294.6 23.32,-257.8 180.72,-257.8 180.72,-294.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-279.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Configuration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-265.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(XML / Annotations / Java)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FACTORY --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FACTORY&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;84.03,-220.8 0,-220.8 0,-184 84.03,-184 84.03,-220.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;42.02&quot; y=&quot;-206&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;BeanFactory&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;42.02&quot; y=&quot;-191.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(lazy, basic)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;FACTORY --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;FACTORY&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M87.19,-257.45C80.21,-249.1 71.75,-238.98 64.05,-229.76&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;66.75,-227.53 57.65,-222.11 61.37,-232.02 66.75,-227.53&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CONTEXT --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CONTEXT&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;225.71,-220.8 102.32,-220.8 102.32,-184 225.71,-184 225.71,-220.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.02&quot; y=&quot;-206&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ApplicationContext&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;164.02&quot; y=&quot;-191.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(eager, full features)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;CONTEXT --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;CONTEXT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M117.34,-257.45C124.63,-249.02 133.47,-238.77 141.5,-229.47&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;143.99,-231.95 147.88,-222.09 138.69,-227.37 143.99,-231.95&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEANS --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEANS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;175.72,-136 28.31,-136 28.31,-84.8 175.72,-84.8 175.72,-136&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-121.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring Beans&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-106.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(instantiated, configured,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-92.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;wired together)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FACTORY&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;FACTORY-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M53.87,-183.62C61.06,-172.84 70.46,-158.73 79.06,-145.84&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;81.94,-147.82 84.58,-137.56 76.12,-143.94 81.94,-147.82&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CONTEXT&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CONTEXT-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M151.77,-183.62C144.27,-172.74 134.43,-158.45 125.48,-145.46&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;128.58,-143.79 120.03,-137.54 122.82,-147.77 128.58,-143.79&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;172.75&quot; y=&quot;-157&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;creates &amp;#x26; wires&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;144.7,-36.8 59.33,-36.8 59.33,0 144.7,0 144.7,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;102.02&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(uses beans)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BEANS&amp;#45;&amp;gt;APP --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BEANS-&gt;APP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M102.02,-84.33C102.02,-73.21 102.02,-60.06 102.02,-48.51&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;105.52,-48.72 102.02,-38.72 98.52,-48.72 105.52,-48.72&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;128.7&quot; y=&quot;-57.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;injected into&lt;/text&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Inversion of Control&lt;/strong&gt;: Container controls bean lifecycle, not the application code&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dependency Injection&lt;/strong&gt;: Dependencies provided automatically; objects don’t look them up&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lazy vs Eager&lt;/strong&gt;: BeanFactory lazy-initializes; ApplicationContext eagerly initializes singletons&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bean scopes&lt;/strong&gt;: singleton (default), prototype, request, session, application, websocket&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lifecycle callbacks&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PostConstruct&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PreDestroy&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;InitializingBean&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;DisposableBean&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — IoC container is the core of Spring&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-bean-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-bean-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Bean Lifecycle&lt;/a&gt; — The container manages every phase of a bean’s lifecycle&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-autowiring&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-autowiring&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Autowiring&lt;/a&gt; — Autowiring is the DI resolution mechanism within the container&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../ejb-context&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-context&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Context&lt;/a&gt; — Both provide access to container services&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../home-interface&quot; class=&quot;internal alias&quot; data-slug=&quot;home-interface&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Home Interface&lt;/a&gt; — EJB uses JNDI lookups; Spring uses DI&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Startup cost&lt;/strong&gt;: ApplicationContext initialization scans classpath, creates all singletons — can be slow with many beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Memory&lt;/strong&gt;: Eager initialization means all singleton beans stay in memory even if unused in the current request&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;BeanFactory vs ApplicationContext&lt;/strong&gt;: Never use raw BeanFactory in modern Spring unless memory is constrained; ApplicationContext is always preferred&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Configuration precedence&lt;/strong&gt;: Java config &gt; annotations &gt; XML — mixing them requires understanding the override order&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-jdbc-template</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-jdbc-template" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-jdbc-template.md" />
    <summary>The Problem Raw JDBC requires manually managing every step of database access: getting a connection, creating a statement, setting parameters, iterating a ResultSet, handling checked SQLExceptions, and closing resources in finally blocks.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Raw JDBC requires manually managing every step of database access: getting a connection, creating a statement, setting parameters, iterating a ResultSet, handling checked SQLExceptions, and closing resources in finally blocks. A simple query becomes 15+ lines of repetitive, error-prone boilerplate.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring JDBC Template provides a template-based API that eliminates JDBC boilerplate. &lt;code class=&quot;notranslate&quot;&gt;JdbcTemplate&lt;/code&gt; wraps the JDBC workflow: it handles connection acquisition, statement creation, parameter binding, result extraction, and cleanup. Developers provide only the SQL and the logic to map results to objects.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;JdbcTemplate&lt;/strong&gt;: Core class wrapping JDBC — execute query/update with automatic resource management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NamedParameterJdbcTemplate&lt;/strong&gt;: Uses named parameters (&lt;code class=&quot;notranslate&quot;&gt;:name&lt;/code&gt;) instead of positional (&lt;code class=&quot;notranslate&quot;&gt;?&lt;/code&gt;) — more readable, especially with many parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RowMapper&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;(ResultSet rs, int rowNum) → T&lt;/code&gt; maps a result set row to a domain object&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResultSetExtractor&lt;/strong&gt;: For custom result extraction (e.g., building a Map from multiple rows)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL scripts&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;ResourceDatabasePopulator&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;ScriptUtils&lt;/code&gt; for executing SQL scripts during testing or setup&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: jdbc_template Pages: 1 --&gt;
&lt;svg width=&quot;533pt&quot; height=&quot;349pt&quot; viewBox=&quot;0.00 0.00 533.00 349.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 344.8)&quot;&gt;
&lt;title&gt;jdbc_template&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-344.8 528.73,-344.8 528.73,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;365.74,-340.8 154.33,-340.8 154.33,-304 365.74,-304 365.74,-340.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-326&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-311.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;jdbcTemplate.query(sql, rowMapper)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JT --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JT&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;305.72,-268 214.35,-268 214.35,-232 305.72,-232 305.72,-268&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-246.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;JdbcTemplate&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;JT --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;JT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M260.04,-303.64C260.04,-296.3 260.04,-287.61 260.04,-279.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;263.54,-279.54 260.04,-269.54 256.54,-279.54 263.54,-279.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- NAMED --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;NAMED&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;186.07,-196 0,-196 0,-159.2 186.07,-159.2 186.07,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;93.04&quot; y=&quot;-181.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;NamedParameterJdbcTemplate&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;93.04&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(:param syntax)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JT&amp;#45;&amp;gt;NAMED --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JT-&gt;NAMED&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M218.76,-231.6C196.73,-222.31 169.38,-210.78 145.82,-200.85&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;147.26,-197.66 136.69,-197 144.54,-204.11 147.26,-197.66&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BARE --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BARE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;330.4,-123.2 189.67,-123.2 189.67,-72 330.4,-72 330.4,-123.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-108.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Raw JDBC&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-94&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(connection, statement,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-79.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;resultset, exception)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JT&amp;#45;&amp;gt;BARE --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JT-&gt;BARE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M248.57,-231.67C242.66,-221.69 236.07,-208.65 233.04,-196 229.22,-180.1 229.63,-175.2 233.04,-159.2 234.85,-150.66 237.96,-141.87 241.44,-133.72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;244.53,-135.38 245.51,-124.83 238.16,-132.46 244.53,-135.38&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ROWM --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ROWM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;369.72,-196 242.35,-196 242.35,-159.2 369.72,-159.2 369.72,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;306.04&quot; y=&quot;-181.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;RowMapper&amp;#x3C;T&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;306.04&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(ResultSet → Object)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JT&amp;#45;&amp;gt;ROWM --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JT-&gt;ROWM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M271.41,-231.6C276.51,-223.79 282.65,-214.39 288.33,-205.69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;291.11,-207.84 293.65,-197.56 285.25,-204.01 291.11,-207.84&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RSE --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RSE&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;524.73,-196 387.35,-196 387.35,-159.2 524.73,-159.2 524.73,-196&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;456.04&quot; y=&quot;-181.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ResultSetExtractor&amp;#x3C;T&gt;&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;456.04&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(custom extraction)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JT&amp;#45;&amp;gt;RSE --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JT-&gt;RSE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M305.99,-232.49C332.68,-222.91 366.62,-210.72 395.47,-200.35&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;396.6,-203.67 404.83,-196.99 394.23,-197.08 396.6,-203.67&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;293.72,-36 226.35,-36 226.35,0 293.72,0 293.72,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;260.04&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- BARE&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;BARE-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M260.04,-71.62C260.04,-63.97 260.04,-55.5 260.04,-47.62&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;263.54,-47.83 260.04,-37.83 256.54,-47.83 263.54,-47.83&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- ROWM&amp;#45;&amp;gt;BARE --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ROWM-&gt;BARE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M295.6,-158.9C291.13,-151.32 285.75,-142.2 280.54,-133.37&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;283.66,-131.76 275.56,-124.93 277.63,-135.32 283.66,-131.76&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RES --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RES&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;456.71,-115.6 383.36,-115.6 383.36,-79.6 456.71,-79.6 456.71,-115.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;420.04&quot; y=&quot;-94&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;List&amp;#x3C;T&gt; / T&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ROWM&amp;#45;&amp;gt;RES --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ROWM-&gt;RES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M332.19,-158.71C348.05,-147.85 368.48,-133.88 385.64,-122.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;387.26,-125.27 393.54,-116.73 383.31,-119.49 387.26,-125.27&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RSE&amp;#45;&amp;gt;RES --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RSE-&gt;RES&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M447.87,-158.9C443.42,-149.26 437.81,-137.11 432.8,-126.25&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;436.05,-124.95 428.68,-117.33 429.7,-127.88 436.05,-124.95&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;JdbcTemplate&lt;/strong&gt;: Simplest template — positional &lt;code class=&quot;notranslate&quot;&gt;?&lt;/code&gt; parameters, automatic resource cleanup&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NamedParameterJdbcTemplate&lt;/strong&gt;: Named &lt;code class=&quot;notranslate&quot;&gt;:param&lt;/code&gt; parameters, better readability, uses SqlParameterSource&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SimpleJdbcTemplate&lt;/strong&gt; (deprecated): Legacy wrapper, replaced by JdbcTemplate&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RowMapper&lt;/strong&gt;: Maps individual rows — reusable, no external state&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResultSetExtractor&lt;/strong&gt;: Processes entire ResultSet (multiple rows, custom structures)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL scripts&lt;/strong&gt;: Execute SQL files via &lt;code class=&quot;notranslate&quot;&gt;ResourceDatabasePopulator&lt;/code&gt; for setup, testing, or migrations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PreparedStatementCallback&lt;/strong&gt;: For full control over PreparedStatement creation and execution&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../java-jdbc&quot; class=&quot;internal alias&quot; data-slug=&quot;java-jdbc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JDBC&lt;/a&gt; — JdbcTemplate is a wrapper over raw JDBC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — JdbcTemplate is a Spring module for data access&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../spring-orm&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-orm&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring ORM&lt;/a&gt; — JdbcTemplate is direct SQL; Spring ORM is object-oriented&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — JdbcTemplate gives SQL control; JPA abstracts SQL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../hql&quot; class=&quot;internal alias&quot; data-slug=&quot;hql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate Query Language&lt;/a&gt; — Both execute database queries; HQL is ORM-based, JdbcTemplate is SQL-based&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Large results&lt;/strong&gt;: JdbcTemplate fetches all results into memory by default — use &lt;code class=&quot;notranslate&quot;&gt;RowCallbackHandler&lt;/code&gt; or streaming for large datasets&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No caching&lt;/strong&gt;: Unlike ORM, JdbcTemplate has no built-in caching — each query hits the database&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No lazy loading&lt;/strong&gt;: All fields must be explicitly selected; no proxy-based lazy loading&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQL injection&lt;/strong&gt;: Always use parameterized queries (&lt;code class=&quot;notranslate&quot;&gt;?&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;:param&lt;/code&gt;), never concatenate user input into SQL strings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DataSource configuration&lt;/strong&gt;: JdbcTemplate needs a properly configured DataSource bean; Spring Boot auto-configures one&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-mvc-exception-handling</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-mvc-exception-handling" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-mvc-exception-handling.md" />
    <summary>The Problem Web application errors (404, 500, validation failures, data access errors) can occur in any controller method.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Web application errors (404, 500, validation failures, data access errors) can occur in any controller method. Without centralized handling, every method needs try-catch blocks, error view selection, and status code mapping — leading to duplicated error-handling code and inconsistent error responses.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring MVC provides a layered exception handling architecture: &lt;code class=&quot;notranslate&quot;&gt;@ExceptionHandler&lt;/code&gt; on controllers handles controller-specific exceptions, &lt;code class=&quot;notranslate&quot;&gt;@ControllerAdvice&lt;/code&gt; provides global exception handling across all controllers, and &lt;code class=&quot;notranslate&quot;&gt;HandlerExceptionResolver&lt;/code&gt; is the lowest-level SPI for complete customization.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Controller-level&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ExceptionHandler(SomeException.class)&lt;/code&gt; methods in the same controller catch specific exceptions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Global-level&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ControllerAdvice&lt;/code&gt; classes contain &lt;code class=&quot;notranslate&quot;&gt;@ExceptionHandler&lt;/code&gt; methods that apply to all controllers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Resolution order&lt;/strong&gt;: Controller-level → ControllerAdvice → HandlerExceptionResolver chain&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error views&lt;/strong&gt;: Exception handler returns ModelAndView with error details and status codes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;REST errors&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@RestControllerAdvice&lt;/code&gt; returns error JSON instead of error views&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResponseEntity&lt;/strong&gt;: ExceptionHandler methods can return &lt;code class=&quot;notranslate&quot;&gt;ResponseEntity&amp;#x3C;ErrorResponse&gt;&lt;/code&gt; for full HTTP response control&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: exception_handling Pages: 1 --&gt;
&lt;svg width=&quot;599pt&quot; height=&quot;288pt&quot; viewBox=&quot;0.00 0.00 599.00 288.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 284.2)&quot;&gt;
&lt;title&gt;exception_handling&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-284.2 595.4,-284.2 595.4,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;488.49,-280.2 365.58,-280.2 365.58,-243.4 488.49,-243.4 488.49,-280.2&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;427.04&quot; y=&quot;-265.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Controller&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;427.04&quot; y=&quot;-251&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@ExceptionHandler&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADVICE --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ADVICE&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;373.05,-195.4 269.02,-195.4 269.02,-158.6 373.05,-158.6 373.05,-195.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;321.04&quot; y=&quot;-180.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ControllerAdvice&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;321.04&quot; y=&quot;-166.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(global)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;ADVICE --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;ADVICE&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M404.3,-243.04C389.21,-231.25 369.19,-215.62 352.57,-202.63&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;354.97,-200.06 344.93,-196.67 350.66,-205.58 354.97,-200.06&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;412.07&quot; y=&quot;-216.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;not handled →&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERR_V --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ERR_V&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;230.04,-36.8 158.03,-36.8 158.03,0 230.04,0 230.04,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;194.04&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Error View&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;194.04&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(error.jsp)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;ERR_V --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;ERR_V&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M444.75,-243.09C478.37,-207.35 544.27,-125.62 500.04,-73.8 467.3,-35.45 319.25,-24.1 241.72,-20.77&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;242.01,-17.28 231.88,-20.38 241.73,-24.27 242.01,-17.28&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;552.49&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;controller-specific&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESOLVER --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESOLVER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;158.07,-110.6 0,-110.6 0,-73.8 158.07,-73.8 158.07,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;79.04&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HandlerExceptionResolver&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;79.04&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(SPI)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADVICE&amp;#45;&amp;gt;RESOLVER --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ADVICE-&gt;RESOLVER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M268.75,-171.21C216.92,-165.71 141.73,-155.49 116.65,-140.6 108.17,-135.57 100.86,-127.85 94.99,-120.1&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;97.99,-118.29 89.43,-112.05 92.23,-122.27 97.99,-118.29&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.34&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;not handled →&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADVICE&amp;#45;&amp;gt;ERR_V --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ADVICE-&gt;ERR_V&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M268.77,-159.71C244.83,-149.49 218.45,-133.76 203.21,-110.6 191.24,-92.41 189.44,-67.62 190.37,-48.47&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;193.85,-48.86 191.14,-38.62 186.87,-48.31 193.85,-48.86&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;234.62&quot; y=&quot;-89.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;global handler&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ERR_J --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ERR_J&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;377.04,-110.6 275.03,-110.6 275.03,-73.8 377.04,-73.8 377.04,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;326.04&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Error JSON&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;326.04&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(for REST APIs)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADVICE&amp;#45;&amp;gt;ERR_J --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ADVICE-&gt;ERR_J&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M321.06,-158.43C321.17,-149.49 321.44,-138.46 322.1,-128.6 322.24,-126.52 322.41,-124.37 322.6,-122.2&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;326.08,-122.63 323.61,-112.32 319.11,-121.92 326.08,-122.63&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;371.57&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;global handler (REST)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- STAT --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;STAT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;491.39,-110.6 394.68,-110.6 394.68,-73.8 491.39,-73.8 491.39,-110.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;443.04&quot; y=&quot;-95.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Status&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;443.04&quot; y=&quot;-81.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(404, 500, etc.)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ADVICE&amp;#45;&amp;gt;STAT --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ADVICE-&gt;STAT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M373.55,-165.91C390.27,-160.62 407.82,-152.62 421.04,-140.6 426.67,-135.47 430.98,-128.6 434.22,-121.69&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;437.46,-123.03 437.92,-112.44 430.96,-120.43 437.46,-123.03&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;463.55&quot; y=&quot;-131.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;set status code&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESOLVER&amp;#45;&amp;gt;ERR_V --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RESOLVER-&gt;ERR_V&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M107.46,-73.45C122.11,-64.3 140.18,-53.02 156.02,-43.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;157.62,-46.26 164.25,-37.99 153.92,-40.32 157.62,-46.26&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;@ExceptionHandler&lt;/strong&gt;: Method-level annotation for handling specific exception types within a controller&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ControllerAdvice&lt;/strong&gt;: Global exception handling across all controllers; also adds model attributes globally&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@RestControllerAdvice&lt;/strong&gt;: @ControllerAdvice + @ResponseBody, for REST APIs returning JSON error responses&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HandlerExceptionResolver&lt;/strong&gt;: Interface for custom exception resolution logic; lowest level&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Status codes&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@ResponseStatus(HttpStatus.NOT_FOUND)&lt;/code&gt; sets HTTP status on exceptions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ErrorAttributes&lt;/strong&gt;: Spring Boot provides default error attributes (timestamp, status, error, message, path)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-mvc&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-mvc&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring MVC&lt;/a&gt; — Exception handling is integral to Spring MVC’s request processing&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — @ExceptionHandler methods live in controllers or @ControllerAdvice&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-form-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-form-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Form Handling&lt;/a&gt; — Validation errors (BindingResult) versus exception handling&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../java-try-catch-finally&quot; class=&quot;internal alias&quot; data-slug=&quot;java-try-catch-finally&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Try-Catch-Finally&lt;/a&gt; — Java try-catch is imperative; Spring MVC exception handling is declarative and cross-cutting&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;HandlerExceptionResolver vs @ExceptionHandler&lt;/strong&gt;: @ExceptionHandler cannot control response status for unhandled exceptions; HandlerExceptionResolver can&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Async exceptions&lt;/strong&gt;: Exceptions in @Async methods or DeferredResult need separate handling (AsyncExceptionHandler)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ResponseStatusException&lt;/strong&gt;: Spring 5+ provides &lt;code class=&quot;notranslate&quot;&gt;ResponseStatusException&lt;/code&gt; for programmatic status + reason without custom exception classes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security exceptions&lt;/strong&gt;: Spring Security exceptions are handled by the Security filter chain, not ControllerAdvice&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-mvc</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-mvc" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-mvc.md" />
    <summary>The Problem Building web applications requires handling HTTP requests, mapping URLs to handlers, parsing parameters, validating input, rendering views, and managing sessions.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="web" label="web" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Building web applications requires handling HTTP requests, mapping URLs to handlers, parsing parameters, validating input, rendering views, and managing sessions. Without a structured framework, web-tier code becomes a messy mix of request handling, business logic, and presentation.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring MVC is a web framework built on the Model-View-Controller pattern, with the DispatcherServlet as the front controller. It cleanly separates concerns: Controllers handle requests, Models hold data, and Views render output. The framework handles request routing, parameter binding, validation, and view resolution transparently.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;DispatcherServlet&lt;/strong&gt;: The front controller receives all HTTP requests and delegates to configured components&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Handler mapping&lt;/strong&gt;: DispatcherServlet consults HandlerMapping to find which controller method handles the request URL&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Controller execution&lt;/strong&gt;: The selected &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt; method executes, processes the request, and returns a ModelAndView&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;View resolution&lt;/strong&gt;: ViewResolver maps logical view names (e.g., “home”) to actual view templates (home.jsp, home.html)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Response rendering&lt;/strong&gt;: View renders the model data into HTML, JSON, or XML&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_mvc Pages: 1 --&gt;
&lt;svg width=&quot;830pt&quot; height=&quot;172pt&quot; viewBox=&quot;0.00 0.00 830.00 172.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 167.97)&quot;&gt;
&lt;title&gt;spring_mvc&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-167.97 825.77,-167.97 825.77,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;99.36,-36.8 0,-36.8 0,0 99.36,0 99.36,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;49.68&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;49.68&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Browser / App)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DS&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;308.3,-86.8 197.6,-86.8 197.6,-50 308.3,-50 308.3,-86.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.95&quot; y=&quot;-72&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;DispatcherServlet&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;252.95&quot; y=&quot;-57.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Front Controller)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M99.66,-30.57C125.75,-37.05 158.2,-45.11 186.43,-52.12&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;185.41,-55.48 195.96,-54.49 187.1,-48.68 185.41,-55.48&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;148.48&quot; y=&quot;-52.35&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;HTTP request&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HM --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HM&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;456,-121.8 351.31,-121.8 351.31,-85 456,-85 456,-121.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;403.65&quot; y=&quot;-107&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HandlerMapping&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;403.65&quot; y=&quot;-92.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(URL → Method)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;HM --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;HM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M308.48,-81.23C318.7,-83.64 329.47,-86.18 339.92,-88.64&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;339.09,-92.04 349.63,-90.92 340.7,-85.22 339.09,-92.04&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- VR --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;VR&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;462.01,-66.8 345.3,-66.8 345.3,-30 462.01,-30 462.01,-66.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;403.65&quot; y=&quot;-52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ViewResolver&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;403.65&quot; y=&quot;-37.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(name → template)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- DS&amp;#45;&amp;gt;VR --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;DS-&gt;VR&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M308.48,-61.07C316.63,-59.97 325.12,-58.83 333.52,-57.7&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;333.94,-61.17 343.38,-56.37 333.01,-54.24 333.94,-61.17&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTRL --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTRL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;673.74,-161.8 574.37,-161.8 574.37,-125 673.74,-125 673.74,-161.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;624.06&quot; y=&quot;-147&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Controller&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;624.06&quot; y=&quot;-132.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(business logic)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HM&amp;#45;&amp;gt;CTRL --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HM-&gt;CTRL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M456.41,-112.88C488.37,-118.73 529.51,-126.27 562.91,-132.38&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;561.96,-135.77 572.43,-134.13 563.23,-128.88 561.96,-135.77&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;515.03&quot; y=&quot;-132.32&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;invokes method&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;DS --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;DS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M573.95,-149.63C517.08,-154.93 421.48,-157.88 345.3,-130.4 322.79,-122.28 300.5,-107.33 283.58,-94.14&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;285.93,-91.54 275.94,-88 281.54,-96.99 285.93,-91.54&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;403.65&quot; y=&quot;-154.97&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;ModelAndView&lt;/text&gt;
&lt;/g&gt;
&lt;!-- MODEL --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;MODEL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;796.42,-161.8 742.42,-161.8 742.42,-125 796.42,-125 796.42,-161.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;769.42&quot; y=&quot;-147&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Model&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;769.42&quot; y=&quot;-132.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(data)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTRL&amp;#45;&amp;gt;MODEL --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTRL-&gt;MODEL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M673.99,-143.4C692.58,-143.4 713.44,-143.4 730.82,-143.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;730.71,-146.9 740.71,-143.4 730.71,-139.9 730.71,-146.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- VIEW --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;VIEW&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;680.07,-66.8 568.05,-66.8 568.05,-30 680.07,-30 680.07,-66.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;624.06&quot; y=&quot;-52&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;View&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;624.06&quot; y=&quot;-37.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(JSP / Thymeleaf)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VR&amp;#45;&amp;gt;VIEW --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;VR-&gt;VIEW&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M462.32,-48.4C491.24,-48.4 526.4,-48.4 556.46,-48.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;556.19,-51.9 566.19,-48.4 556.19,-44.9 556.19,-51.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;821.77,-38.4 717.07,-38.4 717.07,-2.4 821.77,-2.4 821.77,-38.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;769.42&quot; y=&quot;-16.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Response&lt;/text&gt;
&lt;/g&gt;
&lt;!-- VIEW&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;VIEW-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M680.48,-37.57C688.72,-35.97 697.25,-34.3 705.63,-32.66&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;706.27,-36.11 715.41,-30.75 704.93,-29.23 706.27,-36.11&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- RESP&amp;#45;&amp;gt;CLIENT --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;RESP-&gt;CLIENT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M716.86,-10.77C689.65,-6.49 655.66,-2.4 625.06,-2.4 251.95,-2.4 251.95,-2.4 251.95,-2.4 204.57,-2.4 151.12,-6.86 111.21,-11.07&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;110.88,-7.59 101.31,-12.14 111.63,-14.55 110.88,-7.59&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Front controller pattern&lt;/strong&gt;: DispatcherServlet centralizes request handling&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Annotation-based&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@RequestMapping&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@RequestParam&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@ModelAttribute&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;View technology agnostic&lt;/strong&gt;: Works with JSP, Thymeleaf, FreeMarker, Mustache&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;REST support&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@RestController&lt;/code&gt; combines &lt;code class=&quot;notranslate&quot;&gt;@Controller&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;@ResponseBody&lt;/code&gt; for JSON/XML APIs&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data binding&lt;/strong&gt;: Automatically binds request parameters to Java objects&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Validation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Valid&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;BindingResult&lt;/code&gt; for declarative input validation&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Spring MVC is built on Spring Core (IoC, DI)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../dispatcher-servlet&quot; class=&quot;internal alias&quot; data-slug=&quot;dispatcher-servlet&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;DispatcherServlet&lt;/a&gt; — The front controller is the entry point of Spring MVC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-controller&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-controller&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Controller&lt;/a&gt; — @Controller methods handle specific request mappings&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-boot&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-boot&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Boot&lt;/a&gt; — Spring Boot auto-configures Spring MVC with embedded Tomcat&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-form-handling&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-form-handling&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Form Handling&lt;/a&gt; — Form handling and validation in Spring MVC&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../jsp&quot; class=&quot;internal alias&quot; data-slug=&quot;jsp&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JSP&lt;/a&gt; — JSP is a view technology; Spring MVC is a full web framework&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Hidden HttpMethod&lt;/strong&gt;: HTML forms only support GET/POST; Spring’s &lt;code class=&quot;notranslate&quot;&gt;HiddenHttpMethodFilter&lt;/code&gt; converts &lt;code class=&quot;notranslate&quot;&gt;_method=PUT&lt;/code&gt; to actual PUT&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@ModelAttribute vs @RequestParam&lt;/strong&gt;: @ModelAttribute binds complex objects; @RequestParam binds single parameters&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ViewResolver chaining&lt;/strong&gt;: Multiple ViewResolvers with order priority — first match wins&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;async requests&lt;/strong&gt;: DeferredResult and Callable for long-lived async processing in controllers&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-orm</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-orm" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-orm.md" />
    <summary>The Problem Using Hibernate directly requires manually managing SessionFactory, Sessions, and transactions.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="database" label="database" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Using Hibernate directly requires manually managing SessionFactory, Sessions, and transactions. Each operation needs opening a session, beginning a transaction, performing the operation, committing or rolling back, and closing the session. This boilerplate leads to resource leaks and inconsistent transaction boundaries.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring ORM provides a consistent integration layer between Spring and ORM frameworks (Hibernate, JPA, MyBatis). It centralizes SessionFactory creation, provides automatic session management via &lt;code class=&quot;notranslate&quot;&gt;HibernateTemplate&lt;/code&gt;, integrates with Spring’s transaction management, and translates Hibernate exceptions into Spring’s &lt;code class=&quot;notranslate&quot;&gt;DataAccessException&lt;/code&gt; hierarchy.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;LocalSessionFactoryBean&lt;/strong&gt;: Spring creates a Hibernate SessionFactory as a Spring bean, configuring it via Spring’s property management&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;HibernateTransactionManager&lt;/strong&gt;: Connects Hibernate’s transaction API to Spring’s platform transaction management — enables &lt;code class=&quot;notranslate&quot;&gt;@Transactional&lt;/code&gt; on Hibernate operations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Session management&lt;/strong&gt;: Spring opens and closes Hibernate Sessions automatically per operation (OpenSessionInView pattern)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception translation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Repository&lt;/code&gt; + &lt;code class=&quot;notranslate&quot;&gt;PersistenceExceptionTranslationPostProcessor&lt;/code&gt; translates Hibernate exceptions to Spring’s &lt;code class=&quot;notranslate&quot;&gt;DataAccessException&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automatic table creation&lt;/strong&gt;: Hibernate’s &lt;code class=&quot;notranslate&quot;&gt;hibernate.hbm2ddl.auto&lt;/code&gt; property (create, update, validate) automatically generates DDL from entity mappings&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_orm Pages: 1 --&gt;
&lt;svg width=&quot;575pt&quot; height=&quot;262pt&quot; viewBox=&quot;0.00 0.00 575.00 262.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 258.4)&quot;&gt;
&lt;title&gt;spring_orm&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-258.4 571.41,-258.4 571.41,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- SPRING --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SPRING&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;338.73,-254 210.67,-254 210.67,-218 338.73,-218 338.73,-254&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;274.7&quot; y=&quot;-232.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Spring IoC Container&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SF --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SF&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;167.4,-181.6 0,-181.6 0,-144.8 167.4,-144.8 167.4,-181.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;83.7&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;LocalSessionFactoryBean&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;83.7&quot; y=&quot;-152.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;→ Hibernate SessionFactory&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SPRING&amp;#45;&amp;gt;SF --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SPRING-&gt;SF&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M227.98,-217.68C202.24,-208.14 170.04,-196.2 142.59,-186.03&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;143.95,-182.8 133.36,-182.61 141.52,-189.36 143.95,-182.8&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TM --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;TM&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;363.74,-181.6 185.66,-181.6 185.66,-144.8 363.74,-144.8 363.74,-181.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;274.7&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HibernateTransactionManager&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;274.7&quot; y=&quot;-152.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(@Transactional)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SPRING&amp;#45;&amp;gt;TM --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SPRING-&gt;TM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M274.7,-217.86C274.7,-210.41 274.7,-201.46 274.7,-193.04&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;278.2,-193.19 274.7,-183.19 271.2,-193.19 278.2,-193.19&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EXC --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EXC&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;567.41,-181.6 381.99,-181.6 381.99,-144.8 567.41,-144.8 567.41,-181.6&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;474.7&quot; y=&quot;-166.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Exception Translation&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;474.7&quot; y=&quot;-152.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;PersistenceExceptionTranslator&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SPRING&amp;#45;&amp;gt;EXC --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SPRING-&gt;EXC&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M323.88,-217.59C350.96,-208.01 384.8,-196.02 413.57,-185.84&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;414.63,-189.18 422.89,-182.54 412.29,-182.58 414.63,-189.18&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- HIB --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;HIB&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;225.04,-108.8 132.36,-108.8 132.36,-72 225.04,-72 225.04,-108.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.7&quot; y=&quot;-94&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Hibernate&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.7&quot; y=&quot;-79.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(ORM Engine)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SF&amp;#45;&amp;gt;HIB --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;SF-&gt;HIB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M107.67,-144.33C119.15,-135.78 133.08,-125.4 145.55,-116.11&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;147.6,-118.95 153.52,-110.16 143.41,-113.33 147.6,-118.95&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- TM&amp;#45;&amp;gt;HIB --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;TM-&gt;HIB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M250.48,-144.33C238.76,-135.7 224.53,-125.2 211.83,-115.83&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;214.26,-113.28 204.14,-110.16 210.11,-118.91 214.26,-113.28&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- DB --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;DB&lt;/title&gt;
&lt;polygon fill=&quot;#d4edda&quot; stroke=&quot;black&quot; points=&quot;212.38,-36 145.02,-36 145.02,0 212.38,0 212.38,-36&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;178.7&quot; y=&quot;-14.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Database&lt;/text&gt;
&lt;/g&gt;
&lt;!-- HIB&amp;#45;&amp;gt;DB --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;HIB-&gt;DB&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M178.7,-71.64C178.7,-64.3 178.7,-55.61 178.7,-47.44&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;182.2,-47.54 178.7,-37.54 175.2,-47.54 182.2,-47.54&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- APP --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;APP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;180.49,-254.4 12.91,-254.4 12.91,-217.6 180.49,-217.6 180.49,-254.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;96.7&quot; y=&quot;-239.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Application&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;96.7&quot; y=&quot;-225.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Autowired SessionFactory&lt;/text&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;SF --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;SF&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M93.42,-217.13C92.07,-209.78 90.47,-201.08 88.97,-192.88&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;92.46,-192.51 87.21,-183.3 85.57,-193.77 92.46,-192.51&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- APP&amp;#45;&amp;gt;TM --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;APP-&gt;TM&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M141.62,-217.13C165.23,-207.74 194.38,-196.15 219.37,-186.21&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;220.39,-189.57 228.39,-182.62 217.81,-183.06 220.39,-189.57&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Centralized config&lt;/strong&gt;: Hibernate properties (dialect, DDL auto, connection pool) configured in Spring, not hibernate.cfg.xml&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automatic session&lt;/strong&gt;: No session.open()/close() needed — Spring manages the lifecycle&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Transaction integration&lt;/strong&gt;: Standard &lt;code class=&quot;notranslate&quot;&gt;@Transactional&lt;/code&gt; works with Hibernate operations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exception translation&lt;/strong&gt;: Vendor-specific exceptions → Spring’s unified DataAccessException hierarchy&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Automatic DDL&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;hibernate.hbm2ddl.auto&lt;/code&gt; generates database tables from entity classes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lazy loading support&lt;/strong&gt;: OpenSessionInViewFilter keeps session open during view rendering (controversial)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Spring ORM is a Spring module for ORM integration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../hibernate-orm-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;hibernate-orm-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Hibernate ORM Framework&lt;/a&gt; — Spring ORM integrates Hibernate as the ORM provider&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../spring-data-jpa&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-data-jpa&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Data JPA&lt;/a&gt; — Spring Data JPA uses Spring ORM under the hood for Hibernate integration&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-jdbc-template&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-jdbc-template&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring JDBC Template&lt;/a&gt; — Both Spring ORM and JDBC Template are data access approaches in Spring&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../container-managed-persistence&quot; class=&quot;internal alias&quot; data-slug=&quot;container-managed-persistence&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Container-Managed Persistence&lt;/a&gt; — CMP is EJB’s ORM; Spring ORM is more flexible and standalone&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;OpenSessionInView anti-pattern&lt;/strong&gt;: Keeping the session open during view rendering encourages lazy loading outside transactional boundaries, leading to N+1 queries hidden in views&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SessionFactory per data source&lt;/strong&gt;: Multiple databases require separate SessionFactory beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hibernate version conflicts&lt;/strong&gt;: Spring Boot manages Hibernate version; manual dependency management can cause incompatibilities&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DDL auto in production&lt;/strong&gt;: Never use &lt;code class=&quot;notranslate&quot;&gt;hibernate.hbm2ddl.auto=create&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;update&lt;/code&gt; in production — use &lt;code class=&quot;notranslate&quot;&gt;validate&lt;/code&gt; or Flyway/Liquibase&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-security-authentication</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-security-authentication" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-security-authentication.md" />
    <summary>The Problem Applications need to verify user identities and control access based on roles.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="security" label="security" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Applications need to verify user identities and control access based on roles. Hard-coded authentication logic is inflexible, insecure, and doesn’t integrate with standard identity providers. Developers need a pluggable authentication system that supports multiple strategies.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Security Authentication verifies user identity via configurable &lt;code class=&quot;notranslate&quot;&gt;AuthenticationProvider&lt;/code&gt; implementations. The &lt;code class=&quot;notranslate&quot;&gt;UserDetailsService&lt;/code&gt; interface loads user data (username, password hash, roles) from any backend. Role-based authorization restricts access to specific endpoints or methods based on granted authorities.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Authentication request&lt;/strong&gt;: User submits credentials (username/password, token, certificate)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;AuthenticationProvider chain&lt;/strong&gt;: Each provider checks if it can handle the authentication type — first match wins&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UserDetailsService&lt;/strong&gt;: Loads user from database: &lt;code class=&quot;notranslate&quot;&gt;loadUserByUsername(String username) → UserDetails&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Password verification&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;PasswordEncoder.matches(rawPassword, encodedPassword)&lt;/code&gt; — should be BCrypt, not plain text&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;GrantedAuthority&lt;/strong&gt;: User roles returned as &lt;code class=&quot;notranslate&quot;&gt;GrantedAuthority&lt;/code&gt; objects (prefix &lt;code class=&quot;notranslate&quot;&gt;ROLE_&lt;/code&gt; for role-checking)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SecurityContextHolder&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;SecurityContextHolder.getContext().setAuthentication(auth)&lt;/code&gt; — stored in ThreadLocal&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Role-based access&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PreAuthorize(&quot;hasRole(&#039;ADMIN&#039;)&quot;)&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;hasAuthority(&#039;WRITE_PRIVILEGE&#039;)&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph auth_flow {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=TB&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot; fontsize=12]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=10]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  LOGIN [label=&quot;User submits\username/password&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  FILTER [label=&quot;Authentication Filter\n(e.g., UsernamePasswordAuthFilter)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PROVIDER [label=&quot;AuthenticationProvider\n(chain of providers)&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  UDS [label=&quot;UserDetailsService\n(load from DB)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ENC [label=&quot;PasswordEncoder\n(BCrypt match)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CTX [label=&quot;SecurityContextHolder\n(ThreadLocal)&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ROLE [label=&quot;Role Check\n@PreAuthorize\n(hasRole(&#039;ADMIN&#039;))&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ACCESS [label=&quot;Access\nGranted / Denied&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  LOGIN -&gt; FILTER&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  FILTER -&gt; PROVIDER&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PROVIDER -&gt; UDS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  UDS -&gt; ENC&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ENC -&gt; PROVIDER&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  PROVIDER -&gt; CTX [label=&quot;store auth&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  CTX -&gt; ROLE&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  ROLE -&gt; ACCESS&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Multiple providers&lt;/strong&gt;: DAO, LDAP, OAuth2, remember-me, JWT — configured as a provider chain&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UserDetailsService&lt;/strong&gt;: Core interface for loading users from any data source (JDBC, JPA, Mongo)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PasswordEncoder&lt;/strong&gt;: Never store plain-text passwords; BCrypt, SCrypt, Argon2 recommended&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Role hierarchy&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;ROLE_ADMIN &gt; ROLE_USER&lt;/code&gt; — admin inherits user permissions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Remember-me&lt;/strong&gt;: Persistent token-based authentication across browser sessions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Pre-authentication&lt;/strong&gt;: For environments where authentication happens upstream (e.g., SSO, X.509 certs)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — Authentication is a core component of Spring Security&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-security-csrf-jwt&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-csrf-jwt&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security CSRF and JWT&lt;/a&gt; — JWT is an alternative authentication mechanism&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jaas&quot; class=&quot;internal alias&quot; data-slug=&quot;jaas&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JAAS&lt;/a&gt; — JAAS is Java’s standard auth; Spring Security abstracts and improves it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../session-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;session-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Session Authentication&lt;/a&gt; — Session auth stores state on server; JWT is self-contained&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Builds into:&lt;/strong&gt; &lt;a href=&quot;../../jwt-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;jwt-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JWT Authentication&lt;/a&gt; — JWT can be used as a Spring Security authentication provider&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;PasswordEncoder upgrade&lt;/strong&gt;: Migrating from MD5/SHA to BCrypt requires supporting both encoders simultaneously during transition&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UserDetailsService caching&lt;/strong&gt;: Without caching, every request to check auth triggers a database load; use caching layer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ROLE_ prefix&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;hasRole(&#039;ADMIN&#039;)&lt;/code&gt; automatically checks for &lt;code class=&quot;notranslate&quot;&gt;ROLE_ADMIN&lt;/code&gt;; &lt;code class=&quot;notranslate&quot;&gt;hasAuthority(&#039;ADMIN&#039;)&lt;/code&gt; checks for exact string&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ThreadLocal cleanup&lt;/strong&gt;: SecurityContextHolder is ThreadLocal — in async processing, the context doesn’t propagate automatically&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blank passwords&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;PasswordEncoder&lt;/code&gt; should throw exception for blank/null passwords, not silently accept&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-security-csrf-jwt</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-security-csrf-jwt" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-security-csrf-jwt.md" />
    <summary>The Problem Web applications face two critical security challenges: Cross-Site Request Forgery (CSRF) tricks authenticated users into performing unintended actions, and Cross-Origin Resource Sharing (CORS) policies prevent legitimate cross-domain requests.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="security" label="security" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Web applications face two critical security challenges: Cross-Site Request Forgery (CSRF) tricks authenticated users into performing unintended actions, and Cross-Origin Resource Sharing (CORS) policies prevent legitimate cross-domain requests. Additionally, stateless authentication (JWT) needs careful implementation to avoid token theft and replay attacks.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Security provides built-in CSRF protection (synchronizer token pattern, enabled by default for state-changing requests) and CORS configuration (allowing specified origins, methods, and headers). For JWT authentication, Spring Security integrates with &lt;code class=&quot;notranslate&quot;&gt;BearerTokenAuthenticationFilter&lt;/code&gt; to validate signed tokens on every request without server-side session state.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;CSRF protection&lt;/strong&gt;: Server generates a unique token, embedded in forms or sent via header. State-changing requests (POST/PUT/DELETE) must include this token. The &lt;code class=&quot;notranslate&quot;&gt;CsrfFilter&lt;/code&gt; validates it against the stored token&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;CorsFilter&lt;/code&gt; checks &lt;code class=&quot;notranslate&quot;&gt;Origin&lt;/code&gt; header against allowed origins. Spring Security configures via &lt;code class=&quot;notranslate&quot;&gt;.cors()&lt;/code&gt; and &lt;code class=&quot;notranslate&quot;&gt;@CrossOrigin&lt;/code&gt; on controllers&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT authentication&lt;/strong&gt;: Client sends JWT in &lt;code class=&quot;notranslate&quot;&gt;Authorization: Bearer &amp;#x3C;token&gt;&lt;/code&gt; header. &lt;code class=&quot;notranslate&quot;&gt;BearerTokenAuthenticationFilter&lt;/code&gt; extracts and validates token signature and claims&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT validation&lt;/strong&gt;: Verify signature (HMAC or RSA), check expiration (&lt;code class=&quot;notranslate&quot;&gt;exp&lt;/code&gt; claim), verify issuer (&lt;code class=&quot;notranslate&quot;&gt;iss&lt;/code&gt;) and audience (&lt;code class=&quot;notranslate&quot;&gt;aud&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stateless sessions&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;SessionCreationPolicy.STATELESS&lt;/code&gt; — no HTTP session, every request fully authenticated&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: security_protection Pages: 1 --&gt;
&lt;svg width=&quot;675pt&quot; height=&quot;224pt&quot; viewBox=&quot;0.00 0.00 675.00 224.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 220.4)&quot;&gt;
&lt;title&gt;security_protection&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-220.4 671.47,-220.4 671.47,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;g id=&quot;clust1&quot; class=&quot;cluster&quot;&gt;
&lt;title&gt;cluster_jwt&lt;/title&gt;
&lt;polygon fill=&quot;none&quot; stroke=&quot;black&quot; points=&quot;127.36,-62.4 127.36,-208.4 405.78,-208.4 405.78,-62.4 127.36,-62.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;266.57&quot; y=&quot;-191.8&quot; font-family=&quot;Times,serif&quot; font-size=&quot;14.00&quot;&gt;JWT Flow&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CLIENT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;99.36,-73.8 0,-73.8 0,-37 99.36,-37 99.36,-73.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;49.68&quot; y=&quot;-59&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Client&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;49.68&quot; y=&quot;-44.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Browser / App)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CORS_F --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CORS_F&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;241.05,-41.8 153.03,-41.8 153.03,-5 241.05,-5 241.05,-41.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-27&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;CorsFilter&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-12.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(origin check)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;CORS_F --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;CORS_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M99.49,-44.66C113.15,-41.65 128.09,-38.36 142.04,-35.29&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;142.48,-38.78 151.49,-33.21 140.97,-31.94 142.48,-38.78&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JWT_G --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JWT_G&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;258.73,-106.4 135.36,-106.4 135.36,-70.4 258.73,-70.4 258.73,-106.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-84.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Login → JWT Token&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CLIENT&amp;#45;&amp;gt;JWT_G --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CLIENT-&gt;JWT_G&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M99.49,-66.48C107.31,-68.26 115.55,-70.13 123.79,-72&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;122.97,-75.4 133.49,-74.2 124.52,-68.57 122.97,-75.4&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CSRF_F --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CSRF_F&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;402.11,-36.8 294.73,-36.8 294.73,0 402.11,0 402.11,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.42&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;CsrfFilter&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.42&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(token validation)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CORS_F&amp;#45;&amp;gt;CSRF_F --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CORS_F-&gt;CSRF_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M241.25,-21.95C254.3,-21.52 268.93,-21.03 283.05,-20.55&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;282.84,-24.06 292.72,-20.23 282.6,-17.07 282.84,-24.06&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AUTH_F --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AUTH_F&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;564.1,-105.8 438.11,-105.8 438.11,-69 564.1,-69 564.1,-105.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;501.11&quot; y=&quot;-91&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Auth Filter&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;501.11&quot; y=&quot;-76.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(Basic / JWT / Form)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CSRF_F&amp;#45;&amp;gt;AUTH_F --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CSRF_F-&gt;AUTH_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M390.6,-37.25C408.54,-45.47 429.75,-55.19 448.72,-63.87&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;447.06,-66.96 457.61,-67.94 449.97,-60.59 447.06,-66.96&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- API --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;API&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;667.47,-128.8 600.1,-128.8 600.1,-92 667.47,-92 667.47,-128.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;633.79&quot; y=&quot;-114&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Protected&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;633.79&quot; y=&quot;-99.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;API&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTH_F&amp;#45;&amp;gt;API --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AUTH_F-&gt;API&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M564.38,-98.36C572.6,-99.81 580.88,-101.26 588.7,-102.64&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;587.83,-106.04 598.29,-104.33 589.05,-99.15 587.83,-106.04&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JWT_V --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JWT_V&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;244.4,-176 149.68,-176 149.68,-124.8 244.4,-124.8 244.4,-176&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-161.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Validate:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-146.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;signature, exp,&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;197.04&quot; y=&quot;-132.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;iss, aud&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTH_F&amp;#45;&amp;gt;JWT_V --&gt;
&lt;g id=&quot;edge8&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AUTH_F-&gt;JWT_V&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M437.83,-74.36C396.01,-68.4 340.4,-66.04 294.73,-83.4 274.72,-91.01 276.09,-102.88 258.73,-115.4 257.2,-116.5 255.64,-117.6 254.05,-118.68&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;252.43,-115.56 245.98,-123.96 256.27,-121.41 252.43,-115.56&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JWT_H --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;JWT_H&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;397.78,-128.8 299.06,-128.8 299.06,-92 397.78,-92 397.78,-128.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.42&quot; y=&quot;-114&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Authorization:&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;348.42&quot; y=&quot;-99.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Bearer &amp;#x3C;token&gt;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- JWT_G&amp;#45;&amp;gt;JWT_H --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JWT_G-&gt;JWT_H&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M258.8,-97.35C268.22,-98.74 277.94,-100.17 287.34,-101.55&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;286.71,-105 297.11,-102.99 287.73,-98.07 286.71,-105&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JWT_H&amp;#45;&amp;gt;AUTH_F --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JWT_H-&gt;AUTH_F&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M397.93,-103C407.02,-101.61 416.71,-100.13 426.36,-98.66&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;426.79,-102.13 436.15,-97.16 425.73,-95.21 426.79,-102.13&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- JWT_V&amp;#45;&amp;gt;API --&gt;
&lt;g id=&quot;edge9&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;JWT_V-&gt;API&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M244.71,-148.23C286.86,-146.09 350.54,-142.41 405.78,-137.4 469.41,-131.63 542.78,-122.44 588.48,-116.41&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;588.81,-119.9 598.26,-115.11 587.89,-112.96 588.81,-119.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;CSRF default&lt;/strong&gt;: Enabled by default for web apps; disabled automatically for REST APIs (stateless)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS configuration&lt;/strong&gt;: Allowed origins, methods, headers, credentials, and max age via &lt;code class=&quot;notranslate&quot;&gt;CorsConfigurationSource&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@CrossOrigin&lt;/strong&gt;: Per-controller CORS configuration for specific endpoints&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT Bearer tokens&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;spring-boot-starter-oauth2-resource-server&lt;/code&gt; for JWT validation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Token validation&lt;/strong&gt;: Signature, expiration (&lt;code class=&quot;notranslate&quot;&gt;exp&lt;/code&gt;), not-before (&lt;code class=&quot;notranslate&quot;&gt;nbf&lt;/code&gt;), issuer (&lt;code class=&quot;notranslate&quot;&gt;iss&lt;/code&gt;), audience (&lt;code class=&quot;notranslate&quot;&gt;aud&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Stateless architecture&lt;/strong&gt;: JWT enables stateless auth — no server-side session, scales horizontally&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-security&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security&lt;/a&gt; — CSRF, CORS, and JWT are Spring Security modules&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-security-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security Authentication&lt;/a&gt; — JWT provides bearer token authentication&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jwt-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;jwt-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JWT Authentication&lt;/a&gt; — The JWT token concept; Spring Security implements JWT validation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../cors&quot; class=&quot;internal alias&quot; data-slug=&quot;cors&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;CORS&lt;/a&gt; — CORS is an HTTP mechanism; Spring Security configures it&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../jaas&quot; class=&quot;internal alias&quot; data-slug=&quot;jaas&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JAAS&lt;/a&gt; — JAAS is container-managed; Spring Security JWT is application-managed and stateless&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;CSRF with REST APIs&lt;/strong&gt;: If using stateless sessions (JWT), disable CSRF — there’s no session to protect&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSRF with file upload&lt;/strong&gt;: Multipart requests need CSRF token in URL parameter or separate header&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT revocation&lt;/strong&gt;: JWT tokens can’t be revoked before expiration (no server-side state) — use short expirations + refresh tokens&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CORS vs CSRF&lt;/strong&gt;: CORS is about cross-origin access; CSRF is about request forgery — they address different threats&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bearer token storage&lt;/strong&gt;: Storing JWT in localStorage is vulnerable to XSS; httpOnly cookies are safer but require CSRF protection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JWT size&lt;/strong&gt;: Large JWT tokens with many claims can exceed header size limits — keep claims minimal&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-security</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-security" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-security.md" />
    <summary>The Problem Securing enterprise applications requires implementing authentication (who are you?), authorization (what can you do?), and protection against common attacks (CSRF, session fixation, clickjacking).</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="security" label="security" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Securing enterprise applications requires implementing authentication (who are you?), authorization (what can you do?), and protection against common attacks (CSRF, session fixation, clickjacking). Doing this correctly is hard — rolling custom security is error-prone and leads to vulnerabilities.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Spring Security is a comprehensive security framework for Java applications providing authentication, authorization, and protection against common exploits. It uses a filter chain architecture that intercepts every HTTP request, applies configured security rules, and integrates with various authentication providers (database, LDAP, OAuth2, JWT).&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Security filter chain&lt;/strong&gt;: A chain of servlet filters processes every request. Key filters: &lt;code class=&quot;notranslate&quot;&gt;UsernamePasswordAuthenticationFilter&lt;/code&gt; (form login), &lt;code class=&quot;notranslate&quot;&gt;BasicAuthenticationFilter&lt;/code&gt; (HTTP Basic), &lt;code class=&quot;notranslate&quot;&gt;FilterSecurityInterceptor&lt;/code&gt; (authorization)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication&lt;/strong&gt;: User credentials → &lt;code class=&quot;notranslate&quot;&gt;AuthenticationProvider&lt;/code&gt; validates → &lt;code class=&quot;notranslate&quot;&gt;SecurityContextHolder&lt;/code&gt; stores the &lt;code class=&quot;notranslate&quot;&gt;Authentication&lt;/code&gt; object for the request&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authorization&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@PreAuthorize(&quot;hasRole(&#039;ADMIN&#039;)&quot;)&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;AccessDecisionManager&lt;/code&gt; checks if the authenticated user has the required authority&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSRF protection&lt;/strong&gt;: Synchronizer token pattern — generated token embedded in forms, validated on state-changing requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security annotations&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Secured&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PreAuthorize&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostAuthorize&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PreFilter&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;@PostFilter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;UserDetailsService&lt;/strong&gt;: Interface for loading user-specific data (typically from a database)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spring_security Pages: 1 --&gt;
&lt;svg width=&quot;1669pt&quot; height=&quot;45pt&quot; viewBox=&quot;0.00 0.00 1669.00 45.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 40.8)&quot;&gt;
&lt;title&gt;spring_security&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-40.8 1665.4,-40.8 1665.4,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- REQ --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;REQ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;95.36,-36.4 0,-36.4 0,-0.4 95.36,-0.4 95.36,-36.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;47.68&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Request&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FILTERS --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;FILTERS&lt;/title&gt;
&lt;polygon fill=&quot;#ffe5cc&quot; stroke=&quot;black&quot; points=&quot;256.39,-36.4 132.36,-36.4 132.36,-0.4 256.39,-0.4 256.39,-36.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;194.38&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Security Filter Chain&lt;/text&gt;
&lt;/g&gt;
&lt;!-- REQ&amp;#45;&amp;gt;FILTERS --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;REQ-&gt;FILTERS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M95.66,-18.4C103.6,-18.4 112.01,-18.4 120.43,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;120.36,-21.9 130.36,-18.4 120.36,-14.9 120.36,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- AUTH --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AUTH&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;528.15,-36.8 293.39,-36.8 293.39,0 528.15,0 528.15,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;410.77&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Authentication&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;410.77&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(UsernamePasswordAuthenticationFilter)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- FILTERS&amp;#45;&amp;gt;AUTH --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;FILTERS-&gt;AUTH&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M256.81,-18.4C264.82,-18.4 273.24,-18.4 281.84,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;281.73,-21.9 291.73,-18.4 281.73,-14.9 281.73,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- PROVIDER --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PROVIDER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;817.12,-36.8 649.75,-36.8 649.75,0 817.12,0 817.12,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.44&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;AuthenticationProvider&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;733.44&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(DB / LDAP / OAuth2 / JWT)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTH&amp;#45;&amp;gt;PROVIDER --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AUTH-&gt;PROVIDER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M528.45,-18.4C564.48,-18.4 603.71,-18.4 638.05,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;637.98,-21.9 647.98,-18.4 637.98,-14.9 637.98,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;588.95&quot; y=&quot;-21.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;validate credentials&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTHZ --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;AUTHZ&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1339.97,-36.8 1188.6,-36.8 1188.6,0 1339.97,0 1339.97,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1264.28&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Authorization&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1264.28&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(FilterSecurityInterceptor)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACCESS --&gt;
&lt;g id=&quot;node7&quot; class=&quot;node&quot;&gt;
&lt;title&gt;ACCESS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1519.7,-36.4 1376.97,-36.4 1376.97,-0.4 1519.7,-0.4 1519.7,-36.4&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1448.33&quot; y=&quot;-14.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Access Granted/Denied&lt;/text&gt;
&lt;/g&gt;
&lt;!-- AUTHZ&amp;#45;&amp;gt;ACCESS --&gt;
&lt;g id=&quot;edge6&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;AUTHZ-&gt;ACCESS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M1340.38,-18.4C1348.5,-18.4 1356.8,-18.4 1365,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;1364.99,-21.9 1374.99,-18.4 1364.99,-14.9 1364.99,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- CTX --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CTX&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1077.56,-36.8 941.51,-36.8 941.51,0 1077.56,0 1077.56,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1009.53&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SecurityContextHolder&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1009.53&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(ThreadLocal)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PROVIDER&amp;#45;&amp;gt;CTX --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PROVIDER-&gt;CTX&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M817.42,-18.4C853.11,-18.4 894.62,-18.4 929.82,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;929.5,-21.9 939.5,-18.4 929.5,-14.9 929.5,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;879.31&quot; y=&quot;-21.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;store Authentication&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CTX&amp;#45;&amp;gt;AUTHZ --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CTX-&gt;AUTHZ&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M1077.93,-18.4C1108.41,-18.4 1144.79,-18.4 1177.22,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;1176.99,-21.9 1186.99,-18.4 1176.99,-14.9 1176.99,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1133.08&quot; y=&quot;-21.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;check authorities&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESP --&gt;
&lt;g id=&quot;node8&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESP&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;1661.4,-36.8 1556.7,-36.8 1556.7,0 1661.4,0 1661.4,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1609.05&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;HTTP Response&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;1609.05&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(200 / 401 / 403)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- ACCESS&amp;#45;&amp;gt;RESP --&gt;
&lt;g id=&quot;edge7&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;ACCESS-&gt;RESP&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M1519.87,-18.4C1528.2,-18.4 1536.66,-18.4 1544.88,-18.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;1544.78,-21.9 1554.78,-18.4 1544.78,-14.9 1544.78,-21.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Filter chain&lt;/strong&gt;: Modular, ordered chain of security filters, each handling one concern&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication providers&lt;/strong&gt;: DAO (database), LDAP, OAuth2, JWT, remember-me, custom&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authorization methods&lt;/strong&gt;: URL-based (&lt;code class=&quot;notranslate&quot;&gt;.antMatchers().hasRole()&lt;/code&gt;), method-based (&lt;code class=&quot;notranslate&quot;&gt;@PreAuthorize&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CSRF protection&lt;/strong&gt;: Enabled by default for state-changing POST/PUT/DELETE requests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security headers&lt;/strong&gt;: Default headers for XSS, content-type sniffing, clickjacking, HSTS&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Password encoding&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;PasswordEncoder&lt;/code&gt; interface with BCrypt, SCrypt, Argon2 implementations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JSP tag library&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;sec:authorize access=&quot;hasRole(&#039;ADMIN&#039;)&quot;&gt;&lt;/code&gt; for view-level security&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — Spring Security builds on Spring AOP and DI&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-security-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security Authentication&lt;/a&gt; — Core authentication mechanisms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-security-csrf-jwt&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-security-csrf-jwt&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Security CSRF and JWT&lt;/a&gt; — CSRF protection and JWT authentication&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../jaas&quot; class=&quot;internal alias&quot; data-slug=&quot;jaas&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JAAS&lt;/a&gt; — JAAS is the standard Java auth API; Spring Security is the framework approach&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../session-authentication&quot; class=&quot;internal alias&quot; data-slug=&quot;session-authentication&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Session Authentication&lt;/a&gt; — Session auth is simpler; Spring Security provides comprehensive enterprise security&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Filter order&lt;/strong&gt;: Security filters must come before Spring MVC’s DispatcherServlet in the filter chain&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;@EnableWebSecurity vs XML&lt;/strong&gt;: Java config is preferred; mixing with XML can cause unexpected behavior&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SecurityContext persistence&lt;/strong&gt;: In web apps, SecurityContext is stored in the HTTP session — ensure session management is configured&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Async security&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Async&lt;/code&gt; methods lose SecurityContext — use &lt;code class=&quot;notranslate&quot;&gt;SecurityContextRunnable&lt;/code&gt; or &lt;code class=&quot;notranslate&quot;&gt;DelegatingSecurityContextAsyncTaskExecutor&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Whitelabel error page&lt;/strong&gt;: Spring Security’s default error page appears when access is denied — customize with proper error handling&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>spring-spel</title>
    <link href="https://animishraa05.github.io/wiki/java3/spring-spel" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/spring-spel.md" />
    <summary>The Problem Configuration values and bean wiring often require dynamic expressions — accessing system properties, evaluating conditions, performing string operations, or calling methods.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="java" label="java" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Configuration values and bean wiring often require dynamic expressions — accessing system properties, evaluating conditions, performing string operations, or calling methods. Static property files (&lt;code class=&quot;notranslate&quot;&gt;@Value(&quot;${key}&quot;)&lt;/code&gt;) can only do basic key lookups; developers need runtime expression evaluation within the Spring container.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;SpEL (Spring Expression Language) is a powerful expression language that supports querying and manipulating objects at runtime. It can be used in XML and annotation-based configurations, providing dynamic value resolution, method invocation, collection manipulation, and boolean evaluation.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Syntax&lt;/strong&gt;: Expressions start with &lt;code class=&quot;notranslate&quot;&gt;#{&lt;/code&gt; and end with &lt;code class=&quot;notranslate&quot;&gt;}&lt;/code&gt; — e.g., &lt;code class=&quot;notranslate&quot;&gt;#{systemProperties[&#039;user.dir&#039;]}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Property access&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{beanName.property}&lt;/code&gt; accesses any Spring bean’s property&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Method invocation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{beanName.method(args)}&lt;/code&gt; calls methods on beans&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Operators&lt;/strong&gt;: Arithmetic (&lt;code class=&quot;notranslate&quot;&gt;+&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;-&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;*&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;/&lt;/code&gt;), relational (&lt;code class=&quot;notranslate&quot;&gt;==&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;lt&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;gt&lt;/code&gt;), logical (&lt;code class=&quot;notranslate&quot;&gt;and&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;or&lt;/code&gt;, &lt;code class=&quot;notranslate&quot;&gt;not&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collection selection&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{users.?[age &gt; 25]}&lt;/code&gt; filters collections; &lt;code class=&quot;notranslate&quot;&gt;.^&lt;/code&gt; first match, &lt;code class=&quot;notranslate&quot;&gt;.$&lt;/code&gt; last match&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collection projection&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{users.![name]}&lt;/code&gt; extracts specific property from each element&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Safe navigation&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{bean?.property}&lt;/code&gt; — returns null if bean is null instead of NPE&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ternary&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{bean.score &gt; 50 ? &#039;Pass&#039; : &#039;Fail&#039;}&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;graphviz-container&quot; style=&quot;display: flex; justify-content: center; margin: 1.5rem 0; overflow-x: auto;&quot; dir=&quot;auto&quot;&gt;&lt;!--?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?--&gt;

&lt;!-- Generated by graphviz version 15.1.0 (0)
 --&gt;
&lt;!-- Title: spel Pages: 1 --&gt;
&lt;svg width=&quot;694pt&quot; height=&quot;155pt&quot; viewBox=&quot;0.00 0.00 694.00 155.00&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
&lt;g id=&quot;graph0&quot; class=&quot;graph&quot; transform=&quot;scale(1 1) rotate(0) translate(4 150.8)&quot;&gt;
&lt;title&gt;spel&lt;/title&gt;
&lt;polygon fill=&quot;white&quot; stroke=&quot;none&quot; points=&quot;-4,4 -4,-150.8 690.02,-150.8 690.02,4 -4,4&quot;&gt;&lt;/polygon&gt;
&lt;!-- CFG --&gt;
&lt;g id=&quot;node1&quot; class=&quot;node&quot;&gt;
&lt;title&gt;CFG&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;166.29,-99 0,-99 0,-47.8 166.29,-47.8 166.29,-99&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;83.14&quot; y=&quot;-84.2&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Configuration&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;83.14&quot; y=&quot;-69.8&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;@Value(&#039;#{expr}&#039;)&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;83.14&quot; y=&quot;-55.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;&amp;#x3C;property value=&quot;#{expr}&quot; /&gt;&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PARSER --&gt;
&lt;g id=&quot;node2&quot; class=&quot;node&quot;&gt;
&lt;title&gt;PARSER&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;346,-91.8 203.29,-91.8 203.29,-55 346,-55 346,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;274.64&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;SpEL Parser&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;274.64&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(SpelExpressionParser)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- CFG&amp;#45;&amp;gt;PARSER --&gt;
&lt;g id=&quot;edge1&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;CFG-&gt;PARSER&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M166.71,-73.4C174.91,-73.4 183.24,-73.4 191.44,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;191.41,-76.9 201.41,-73.4 191.41,-69.9 191.41,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- EVAL --&gt;
&lt;g id=&quot;node3&quot; class=&quot;node&quot;&gt;
&lt;title&gt;EVAL&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;455.04,-91.8 383,-91.8 383,-55 455.04,-55 455.04,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;419.02&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Evaluation&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;419.02&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Context&lt;/text&gt;
&lt;/g&gt;
&lt;!-- PARSER&amp;#45;&amp;gt;EVAL --&gt;
&lt;g id=&quot;edge2&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;PARSER-&gt;EVAL&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M346.42,-73.4C354.86,-73.4 363.3,-73.4 371.29,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;371.08,-76.9 381.08,-73.4 371.08,-69.9 371.08,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;!-- BEANS --&gt;
&lt;g id=&quot;node4&quot; class=&quot;node&quot;&gt;
&lt;title&gt;BEANS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;686.02,-146.8 569.96,-146.8 569.96,-110 686.02,-110 686.02,-146.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-132&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;ApplicationContext&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-117.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;(beans)&lt;/text&gt;
&lt;/g&gt;
&lt;!-- EVAL&amp;#45;&amp;gt;BEANS --&gt;
&lt;g id=&quot;edge3&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EVAL-&gt;BEANS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M455.32,-84.29C461.23,-86.05 467.3,-87.81 473.04,-89.4 501.06,-97.17 532.12,-105.16 558.97,-111.87&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;557.78,-115.18 568.33,-114.2 559.47,-108.39 557.78,-115.18&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;512.5&quot; y=&quot;-112.27&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;bean references&lt;/text&gt;
&lt;/g&gt;
&lt;!-- SYS --&gt;
&lt;g id=&quot;node5&quot; class=&quot;node&quot;&gt;
&lt;title&gt;SYS&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;685,-91.8 570.97,-91.8 570.97,-55 685,-55 685,-91.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-77&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;System Properties&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-62.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Environment&lt;/text&gt;
&lt;/g&gt;
&lt;!-- EVAL&amp;#45;&amp;gt;SYS --&gt;
&lt;g id=&quot;edge4&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EVAL-&gt;SYS&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M455.13,-73.4C483.64,-73.4 524.69,-73.4 559.52,-73.4&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;559.08,-76.9 569.08,-73.4 559.08,-69.9 559.08,-76.9&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;512.5&quot; y=&quot;-76.4&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;10.00&quot;&gt;system properties&lt;/text&gt;
&lt;/g&gt;
&lt;!-- RESULT --&gt;
&lt;g id=&quot;node6&quot; class=&quot;node&quot;&gt;
&lt;title&gt;RESULT&lt;/title&gt;
&lt;polygon fill=&quot;#f0f4ff&quot; stroke=&quot;black&quot; points=&quot;662.67,-36.8 593.3,-36.8 593.3,0 662.67,0 662.67,-36.8&quot;&gt;&lt;/polygon&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-22&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Evaluated&lt;/text&gt;
&lt;text xml:space=&quot;preserve&quot; text-anchor=&quot;middle&quot; x=&quot;627.99&quot; y=&quot;-7.6&quot; font-family=&quot;Helvetica,sans-Serif&quot; font-size=&quot;12.00&quot;&gt;Value&lt;/text&gt;
&lt;/g&gt;
&lt;!-- EVAL&amp;#45;&amp;gt;RESULT --&gt;
&lt;g id=&quot;edge5&quot; class=&quot;edge&quot;&gt;
&lt;title&gt;EVAL-&gt;RESULT&lt;/title&gt;
&lt;path fill=&quot;none&quot; stroke=&quot;black&quot; d=&quot;M455.13,-64.07C490.19,-54.75 544.2,-40.4 582.3,-30.28&quot;&gt;&lt;/path&gt;
&lt;polygon fill=&quot;black&quot; stroke=&quot;black&quot; points=&quot;582.85,-33.75 591.62,-27.8 581.06,-26.98 582.85,-33.75&quot;&gt;&lt;/polygon&gt;
&lt;/g&gt;
&lt;/g&gt;
&lt;/svg&gt;
&lt;/div&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Dynamic evaluation&lt;/strong&gt;: Expressions are evaluated at runtime, not compile time&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bean access&lt;/strong&gt;: Directly reference Spring beans by name (&lt;code class=&quot;notranslate&quot;&gt;#{myBean.count}&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Null-safe&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;?.&lt;/code&gt; operator prevents NullPointerException in navigation chains&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Collection operators&lt;/strong&gt;: Selection (&lt;code class=&quot;notranslate&quot;&gt;?[]&lt;/code&gt;), projection (&lt;code class=&quot;notranslate&quot;&gt;![]&lt;/code&gt;), sorting according to a property&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Type operators&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;T(java.lang.Math).PI&lt;/code&gt; references static types and methods&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration&lt;/strong&gt;: Works with &lt;code class=&quot;notranslate&quot;&gt;@Value&lt;/code&gt;, XML &lt;code class=&quot;notranslate&quot;&gt;&amp;#x3C;property&gt;&lt;/code&gt;, security annotations, and more&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-framework&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-framework&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Framework&lt;/a&gt; — SpEL is a Spring Core module&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../spring-ioc-container&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-ioc-container&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring IoC Container&lt;/a&gt; — SpEL evaluates within the container’s context&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../spring-annotations&quot; class=&quot;internal alias&quot; data-slug=&quot;spring-annotations&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Spring Annotations&lt;/a&gt; — @Value with SpEL provides dynamic property injection&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Contrasts with:&lt;/strong&gt; &lt;a href=&quot;../../ejb-ql&quot; class=&quot;internal alias&quot; data-slug=&quot;ejb-ql&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;EJB Query Language (EJB-QL)&lt;/a&gt; — EJB-QL queries entities; SpEL queries beans and system properties&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-operators&quot; class=&quot;internal alias&quot; data-slug=&quot;java-operators&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Operators&lt;/a&gt; — SpEL operators extend Java’s with collection-safe operations&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Syntax confusion&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;#{}&lt;/code&gt; (SpEL evaluation) vs &lt;code class=&quot;notranslate&quot;&gt;${}&lt;/code&gt; (property placeholder) — they can be nested: &lt;code class=&quot;notranslate&quot;&gt;#{${property}}&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Complex SpEL expressions are evaluated on every access — avoid in hot paths&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Method invocation&lt;/strong&gt;: Only public methods on beans can be called; private/static methods require T() type operator&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Security&lt;/strong&gt;: SpEL can call any bean method and access any property — never use user-provided input in SpEL expressions (security risk)&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry><entry>
    <title>test-driven-development</title>
    <link href="https://animishraa05.github.io/wiki/java3/test-driven-development" />
    <link rel="alternate" type="text/markdown" href="https://animishraa05.github.io/wiki/java3/test-driven-development.md" />
    <summary>The Problem Writing code without tests leads to bugs that are found late, regression failures when refactoring, and code that’s hard to change with confidence.</summary>
    <published>2026-05-13T00:00:00.000Z</published>
    <updated>2026-05-13T00:00:00.000Z</updated>
    <publishedTime>May 13, 2026</publishedTime>
    <updatedTime>May 13, 2026</updatedTime>
    <category term="dev" label="dev" />
<category term="testing" label="testing" />
    <author>
      <name>Animesh Mishra</name>
      <email>animesh.mishra818@gmail.com</email>
    </author>
    <content type="html">&lt;h2 id=&quot;the-problem&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;The Problem&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#the-problem&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Writing code without tests leads to bugs that are found late, regression failures when refactoring, and code that’s hard to change with confidence. Testing after coding often gets skipped due to deadlines. Developers need a discipline that ensures code is tested from the start.&lt;/p&gt;
&lt;h2 id=&quot;core-idea&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Core Idea&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#core-idea&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p dir=&quot;auto&quot;&gt;Test-Driven Development (TDD) is a software development practice where tests are written before the implementation code. The cycle is: Red (write a failing test) → Green (write the minimal code to pass) → Refactor (improve code while tests stay green). This ensures 100% test coverage of specified behavior and drives clean, testable design.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;How It Works&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#how-it-works&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ol dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Red&lt;/strong&gt;: Write a test for the NEXT piece of functionality. Run it — it should fail (red) because the code doesn’t exist yet&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Green&lt;/strong&gt;: Write the SIMPLEST possible implementation code to make the test pass. Don’t optimize, don’t over-engineer&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Refactor&lt;/strong&gt;: With tests passing (green), improve the code: remove duplication, extract methods, rename variables. Tests ensure refactoring doesn’t break anything&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Repeat&lt;/strong&gt;: Add the next test, see it fail, implement, refactor. Each cycle is 30-60 seconds&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;JUnit + Mockito&lt;/strong&gt;: JUnit provides the test framework; Mockito isolates the unit under test by mocking its dependencies (services, repositories)&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;visual-explanation&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Visual Explanation&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#visual-explanation&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;figure data-rehype-pretty-code-figure=&quot;&quot;&gt;&lt;pre class=&quot;notranslate&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e&quot; tabindex=&quot;0&quot; data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot;&gt;&lt;span class=&quot;clipboard-button&quot; type=&quot;button&quot; aria-label=&quot;copy source&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;copy-icon&quot;&gt;&lt;use href=&quot;#github-copy&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 -8 24 24&quot; fill=&quot;currentColor&quot; stroke=&quot;none&quot; stroke-width=&quot;0&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;check-icon&quot;&gt;&lt;use href=&quot;#github-check&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/span&gt;&lt;code data-language=&quot;dot&quot; data-theme=&quot;github-light github-dark&quot; style=&quot;display: grid;&quot; class=&quot;notranslate&quot;&gt;&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;digraph tdd_cycle {&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  rankdir=LR&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  node [shape=box style=filled fillcolor=&quot;#f0f4ff&quot; fontname=&quot;Helvetica&quot; fontsize=12]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  edge [fontname=&quot;Helvetica&quot; fontsize=10]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RED [label=&quot;RED\nWrite failing test\n(test doesn&#039;t compile\nor assertion fails)&quot; fillcolor=&quot;#ffe5cc]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  GREEN [label=&quot;GREEN\nWrite minimal code\n(make test pass)&quot; fillcolor=&quot;#d4edda]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REFACTOR [label=&quot;REFACTOR\nImprove code\n(duplication, naming,\nstructure)&quot; fillcolor=&quot;#cce5ff]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  NEXT [label=&quot;Next Test&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt; &lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  RED -&gt; GREEN [label=&quot;1. implement&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  GREEN -&gt; REFACTOR [label=&quot;2. all green&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REFACTOR -&gt; RED [label=&quot;3. add next test&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;  REFACTOR -&gt; NEXT [label=&quot;loop&quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span data-line=&quot;&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;h2 id=&quot;key-properties&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Key Properties&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#key-properties&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Test-first&lt;/strong&gt;: Tests are written before implementation, not after&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Small cycles&lt;/strong&gt;: Red-Green-Refactor in 30-60 second iterations&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Minimal implementation&lt;/strong&gt;: Write just enough code to pass the test — no more&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Continuous refactoring&lt;/strong&gt;: Improve code quality with the safety net of passing tests&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Design driver&lt;/strong&gt;: TDD naturally drives decoupled, testable designs (dependency injection, interfaces)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mockito integration&lt;/strong&gt;: &lt;code class=&quot;notranslate&quot;&gt;@Mock&lt;/code&gt; for dependencies, &lt;code class=&quot;notranslate&quot;&gt;@InjectMocks&lt;/code&gt; for the system under test&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test coverage&lt;/strong&gt;: Every line of production code exists because a test required it&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;connections&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Connections&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#connections&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../junit-testing&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-testing&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Testing&lt;/a&gt; — JUnit is the testing framework used in TDD&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Built from:&lt;/strong&gt; &lt;a href=&quot;../../junit-annotations-lifecycle&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-annotations-lifecycle&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Annotations and Lifecycle&lt;/a&gt; — Lifecycle hooks structure TDD test fixtures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../junit-parameterized-tests&quot; class=&quot;internal alias&quot; data-slug=&quot;junit-parameterized-tests&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;JUnit Parameterized Tests&lt;/a&gt; — Parameterized tests express TDD edge case coverage&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;../../java-methods&quot; class=&quot;internal alias&quot; data-slug=&quot;java-methods&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;Java Methods&lt;/a&gt; — TDD drives clean method design with single responsibilities&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases--gotchas&quot; dir=&quot;auto&quot;&gt;&lt;span class=&quot;highlight-span&quot;&gt;Edge Cases &amp;#x26; Gotchas&lt;/span&gt;&lt;a data-role=&quot;anchor&quot; data-no-popover href=&quot;#edge-cases--gotchas&quot; class=&quot;internal&quot;&gt;&lt;span class=&quot;indicator-hook&quot;&gt;&lt;/span&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot;&gt;&lt;use href=&quot;#github-anchor&quot;&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul dir=&quot;auto&quot;&gt;
&lt;li&gt;&lt;strong&gt;TDD is a discipline, not a tool&lt;/strong&gt;: It takes practice to write tests first consistently — especially when under pressure&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mocking everything&lt;/strong&gt;: Over-mocking leads to brittle tests that break when implementation details change&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Testing private methods&lt;/strong&gt;: Don’t test private methods directly — test the public API that uses them&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Integration vs unit&lt;/strong&gt;: TDD works best at the unit level; integration tests follow different patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Red phase must fail&lt;/strong&gt;: If the test passes before implementation, it tests the wrong thing or duplicates an existing test&lt;/li&gt;
&lt;/ul&gt;</content>
  </entry>
</feed>