<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Spring Data JPA &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/spring-data-jpa/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Fri, 06 Jan 2023 16:37:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>Spring Data JPA &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Spring Data JPA: Requested bean is currently in creation: Is there an unresolvable circular reference?</title>
		<link>https://myshittycode.com/2015/09/10/spring-data-jpa-requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-reference/</link>
					<comments>https://myshittycode.com/2015/09/10/spring-data-jpa-requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-reference/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Thu, 10 Sep 2015 18:29:37 +0000</pubDate>
				<category><![CDATA[Programming Language]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[Spring Data JPA]]></category>
		<guid isPermaLink="false">http://myshittycode.com/?p=842</guid>

					<description><![CDATA[<p>PROBLEM Let&#8217;s assume we have the following Spring Data JPA repository&#8230; &#8230; this repository has some custom implementation&#8230; &#8230; this custom implementation depends on the original repository to reuse existing APIs&#8230; When we run the code, we get the following exception:- SOLUTION To fix the circular reference problem, instead of auto-wiring ProjectRepository using the constructor, [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2015/09/10/spring-data-jpa-requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-reference/">Spring Data JPA: Requested bean is currently in creation: Is there an unresolvable circular reference?</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">PROBLEM</h2>



<p>Let&#8217;s assume we have the following Spring Data JPA repository&#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public interface ProjectRepository extends JpaRepository&lt;Project, Long&gt;, ProjectRepositoryCustom {
    Project findByName(String name);
}
</pre></div>


<p>&#8230; this repository has some custom implementation&#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public interface ProjectRepositoryCustom {
    Project doCustom(String name);
}
</pre></div>


<p>&#8230; this custom implementation depends on the original repository to reuse existing APIs&#8230;</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; title: ; notranslate">
public final class ProjectRepositoryImpl implements ProjectRepositoryCustom {
    private final ProjectRepository projectRepository;

    @Autowired
    public ProjectRepositoryImpl(final ProjectRepository projectRepository) {
        this.projectRepository = projectRepository;
    }

    @Override
    public Project doCustom(final String name) {
        final Project project = projectRepository.findByName(name);
        return ...
    }
}
</pre></div>


<p>When we run the code, we get the following exception:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name &#039;projectRepositoryImpl&#039;: Requested bean
is currently in creation: Is there an unresolvable circular reference?
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:347)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
</pre></div>


<h2 class="wp-block-heading">SOLUTION</h2>



<p>To fix the circular reference problem, instead of auto-wiring <code>ProjectRepository</code> using the constructor, auto-wire using the field or setter method:-</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: java; highlight: [2,3,5,6,7,8]; title: ; notranslate">
public final class ProjectRepositoryImpl implements ProjectRepositoryCustom {
    // this field cannot be `final` anymore
    private ProjectRepository projectRepository;

    @Autowired
    public void setProjectRepository(final ProjectRepository projectRepository) {
        this.projectRepository = projectRepository;
    }

    @Override
    public Project doCustom(final String name) {
        final Project project = projectRepository.findByName(name);
        return ...
    }
}
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2015/09/10/spring-data-jpa-requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-reference/">Spring Data JPA: Requested bean is currently in creation: Is there an unresolvable circular reference?</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2015/09/10/spring-data-jpa-requested-bean-is-currently-in-creation-is-there-an-unresolvable-circular-reference/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">842</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching using Disk

Served from: myshittycode.com @ 2026-02-22 06:06:24 by W3 Total Cache
-->