Circular reference when upgrading spring security from 3.X to 4.X
<p>I'm in the process of upgrading spring security from 3.2.5.RELEASE to 4.0.3.RELEASE. According to <a href="http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-jc.html" rel="nofollow">http://docs.spring.io/spring-security/site/migrate/current/3-to-4/html5/migrate-3-to-4-jc.html</a> the properties of ProviderManager should now be initialized via a constructor. Therefore I changed:</p>

<pre><code>    &lt;beans:bean id="authenticationManager"
        class="org.springframework.security.authentication.ProviderManager"&gt;
    &lt;beans:property name="providers"&gt;
        &lt;beans:list&gt;
            &lt;beans:ref bean="daoAuthenticationProvider" /&gt;
        &lt;/beans:list&gt;
    &lt;/beans:property&gt;
&lt;/beans:bean&gt;
&lt;beans:bean id="daoAuthenticationProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
    &lt;beans:property name="userDetailsService" ref="userDetailsManager" /&gt;
...
&lt;/beans:bean&gt;
&lt;beans:bean id="userDetailsManager"
    class="org.springframework.security.provisioning.JdbcUserDetailsManager"&gt;
    &lt;beans:property name="authenticationManager"
        ref="authenticationManager" /&gt;
...
&lt;/beans:bean&gt;
</code></pre>

<p>to</p>

<pre><code>&lt;beans:bean id="authenticationManager"
        class="org.springframework.security.authentication.ProviderManager"&gt;
    &lt;beans:constructor-arg name="providers"&gt;
        &lt;beans:list&gt;
            &lt;beans:ref bean="daoAuthenticationProvider" /&gt;
        &lt;/beans:list&gt;
    &lt;/beans:constructor-arg&gt;
&lt;/beans:bean&gt;
&lt;beans:bean id="daoAuthenticationProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
    &lt;beans:property name="userDetailsService" ref="userDetailsManager" /&gt;
...
&lt;/beans:bean&gt;
&lt;beans:bean id="userDetailsManager"
    class="org.springframework.security.provisioning.JdbcUserDetailsManager"&gt;
    &lt;beans:property name="authenticationManager"
        ref="authenticationManager" /&gt;
...
&lt;/beans:bean&gt;
</code></pre>

<p>The result is a circular reference error on startup:</p>

<pre><code>ERROR 2016-01-20 11:46:18,511 [RMI TCP Connection(4)-127.0.0.1] (?:?) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityServicesDelegator' defined in class path resource [web-security-context-ui.xml]: 
Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in class path resource [web-security-context-ui.xml]: 
Cannot resolve reference to bean 'daoAuthenticationProvider' while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'daoAuthenticationProvider' defined in class path resource [web-security-context-ui.xml]: 
Cannot resolve reference to bean 'userDetailsManager' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsManager' defined in class path resource [web-security-context-ui.xml]: 
Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'authenticationManager': Requested bean is currently in creation: 
Is there an unresolvable circular reference?
</code></pre>

<p>Any ideas on how to circumvent this issue?</p>