Spring security : Cannot resolve reference to bean while setting constructor argument
<p>I am implementing Remember me in spring security.And here is my configuration</p>

<pre><code>&lt;bean id="rememberMeServices"
          class="com.spring.security.service.WMPersistentTokenBasedRememberMeServices"&gt;
        &lt;constructor-arg name="userDetailsService" ref="loginService"/&gt;
        &lt;property name="tokenValiditySeconds" value="300"&gt;&lt;/property&gt;
 &lt;/bean&gt;


&lt;security:http auto-config="false" use-expressions="true" entry-point-ref="appAuthenticationEntryPoint"&gt;
        &lt;!-- Interceptor urls --&gt;
        &lt;security:remember-me user-service-ref="#{rememberMeServices.getUserDetailsServiceInstance()}" token-repository-ref="#{rememberMeServices.getTokenRepository()}" /&gt;
&lt;/security:http&gt;
</code></pre>

<p>And my WMPersistentTokenBasedRememberMeServices looks like </p>

<pre><code>public class WMPersistentTokenBasedRememberMeServices extends PersistentTokenBasedRememberMeServices {

    private static final String key = "WM_APP_KEY";

    private static final PersistentTokenRepository tokenRepository = new InMemoryTokenRepositoryImpl();

    public WMPersistentTokenBasedRememberMeServices(UserDetailsService userDetailsService) {
        super(key, userDetailsService, tokenRepository);
    }

    public PersistentTokenRepository getTokenRepository() {
        return tokenRepository;
    }

    public UserDetailsService getUserDetailsServiceInstance()
    {
        return getUserDetailsService();
    }
} 
</code></pre>

<p>But When I deploy application with above configuratio,I am getter below error</p>

<pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#61fc8560': Cannot resolve reference to bean 'org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices#0' while setting bean property 'logoutHandlers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices#0': Cannot resolve reference to bean '#{rememberMeServices.getTokenRepository()}' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinition
Exception: No bean named 'org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl@2a13c5e' is defined


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices#0': Cannot resolve reference to bean '#{rememberMeServices.getTokenRepository()}' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl@2a13c5e' is defined
</code></pre>

<p>When I remove using spring expression language in </p>

<pre><code> &lt;security:remember-me ...&gt;
</code></pre>

<p>tag and provide valid user ref instance,it is working fine.</p>

<p>But when I use spring expression language it is failing with above error.I doubt with ordering of bean creation.</p>

<p>Any one having Idea about this error ?</p>