title: Spring security cannot resolve reference to bean
body: <p>I'm getting the error below while trying to deploy my jsf project with spring security integrated. I just started using Spring security today since the java ee security with the security realms were too much of an hassle. I watched <a href="https://www.youtube.com/watch?v=DCd2O0At_fA" rel="nofollow">this tutorial</a>. So I'm not sure what this error means really. I also started gradle today so I included the dependencies I put there just in case.</p>
  
  <p>(I'll put the error as quote at the bottom of the page).</p>
  
  <pre><code>cannot Deploy InscriptionTemp2 deploy is failing=Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#1' while setting bean property 'sourceList' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#1': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [6]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.security.provisioning.JdbcUserDetailsManager] for bean with name 'org.springframework.security.provisioning.JdbcUserDetailsManager#0' defined in null: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/support/JdbcDaoSupport. Please see server.log for more details.
  </code></pre>
  
  <p>applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:jee="http://www.springframework.org/schema/jee"
         xmlns:lang="http://www.springframework.org/schema/lang"
         xmlns:util="http://www.springframework.org/schema/util"
         xmlns:task="http://www.springframework.org/schema/task"
         xmlns:sec="http://www.springframework.org/schema/security"
  
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd"&gt;
  
      &lt;!-- begin Spring Security config --&gt;
      &lt;sec:global-method-security secured-annotations="enabled" /&gt;
  
      &lt;!-- Don't SSL encrypt static resources --&gt;
      &lt;sec:http pattern="/resources/**" security="none"/&gt;
  
      &lt;sec:http auto-config="true" &gt;
  
          &lt;!-- On Glassfish, dev ports are 8080 and 8181, whereas on
          production its 80 and 443 --&gt;
          &lt;sec:port-mappings&gt;
              &lt;sec:port-mapping http="8080" https="8181"/&gt;
          &lt;/sec:port-mappings&gt;
  
          &lt;sec:intercept-url 
              pattern="/faces/restricted/user/**" 
              access="ROLE_ADMIN, ROLE_ADMIN" requires-channel="https" /&gt;
          &lt;sec:intercept-url 
              pattern="/faces/restricted/admins/**" 
              access="ROLE_ADMIN" requires-channel="https" /&gt;
          &lt;sec:intercept-url 
              pattern="/**" 
              access="IS_AUTHENTICATED_ANONYMOUSLY"/&gt;
  
          &lt;!-- Use O/S provided login window
          &lt;http-basic /&gt;
          --&gt;
          &lt;!-- Use custom form for login --&gt;
          &lt;sec:form-login 
              login-processing-url="/j_spring_security_check"
              login-page="/faces/login.xhtml" 
              authentication-success-handler-ref="myAuthenticationHandler"
              authentication-failure-url="/faces/loginerror.xhtml"/&gt;
  
          &lt;sec:logout logout-url="/j_spring_security_logout" 
                      invalidate-session="true" 
                      logout-success-url="/faces/index.xhtml" /&gt;
  
      &lt;/sec:http&gt;
  
      &lt;sec:authentication-manager alias="authenticationManager"&gt;
          &lt;sec:authentication-provider&gt;
              &lt;sec:password-encoder ref="encoderBean"&gt;
                  &lt;sec:salt-source user-property="username"/&gt;
              &lt;/sec:password-encoder&gt;
              &lt;sec:jdbc-user-service data-source-ref="dataSource" /&gt; 
  
              &lt;!-- if not using a database for accounts, hard-code them here
             &lt;sec:user-service&gt;
                 &lt;sec:user name="admin" password="admin" authorities="ROLE_ADMIN, ROLE_MEMBER" /&gt;
                 &lt;sec:user name="member" password="member" authorities="ROLE_MEMBER" /&gt;
             &lt;/sec:user-service&gt;
              --&gt;
          &lt;/sec:authentication-provider&gt;
      &lt;/sec:authentication-manager&gt;
  
      &lt;bean id="myAuthenticationHandler" class="com.activee.utils.MyAuthenticationHandler" /&gt;
  
      &lt;bean id="encoderBean" class="org.springframework.security.authentication.encoding.ShaPasswordEncoder"&gt;
          &lt;constructor-arg value="512" /&gt;
          &lt;property name="iterations" value="1024"/&gt;
      &lt;/bean&gt;
  
  
      &lt;!-- Server managed connection pool accessed via JNDI --&gt;
      &lt;jee:jndi-lookup id="dataSource" jndi-name="jdbc/inscriptiontestDS"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>my gradle dependencies:</p>
  
  <pre><code>dependencies {
      compile 'org.springframework.security:spring-security-web:4.0.1.RELEASE'
      compile 'org.springframework.security:spring-security-config:4.0.1.RELEASE'
      compile 'org.springframework.security:spring-security-core:4.0.1.RELEASE'    
  }
  </code></pre>
  
  <p>my web.xml</p>
  
  <pre><code> &lt;!-- Security configuration
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.request.RequestContextListener&lt;/listener-class&gt;
      &lt;/listener&gt;  --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
          &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt;
          &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;
      &lt;/filter-mapping&gt;
      &lt;!-- end spring configuration --&gt;
  </code></pre>
  
  <p>and as promised for your greatest pleasure, the error as quote :</p>
  
  <blockquote>
    <p>cannot Deploy InscriptionTemp2 deploy is failing=Error occurred during
    deployment: Exception while loading the app :
    java.lang.IllegalStateException: ContainerBase.addChild: start:
    org.apache.catalina.LifecycleException:
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'org.springframework.security.filterChains':
    Cannot resolve reference to bean
    'org.springframework.security.web.DefaultSecurityFilterChain#1' while
    setting bean property 'sourceList' with key <a href="https://www.youtube.com/watch?v=DCd2O0At_fA" rel="nofollow">1</a>; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.web.DefaultSecurityFilterChain#1':
    Cannot resolve reference to bean
    'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0'
    while setting constructor argument with key [6]; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0':
    Cannot resolve reference to bean
    'org.springframework.security.authentication.ProviderManager#0' while
    setting bean property 'authenticationManager'; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authentication.ProviderManager#0':
    Cannot resolve reference to bean
    'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
    while setting constructor argument; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0':
    FactoryBean threw exception on object creation; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authenticationManager': Cannot resolve
    reference to bean
    'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
    while setting constructor argument with key [0]; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0':
    Cannot resolve reference to bean
    'org.springframework.security.provisioning.JdbcUserDetailsManager#0'
    while setting bean property 'userDetailsService'; nested exception is
    org.springframework.beans.factory.CannotLoadBeanClassException: Error
    loading class
    [org.springframework.security.provisioning.JdbcUserDetailsManager] for
    bean with name
    'org.springframework.security.provisioning.JdbcUserDetailsManager#0'
    defined in null: problem with class file or dependent class; nested
    exception is java.lang.NoClassDefFoundError:
    org/springframework/jdbc/core/support/JdbcDaoSupport. Please see
    server.log for more details.</p>
  </blockquote>
  
  <p>and I'll put my login bean here because I find it weird.</p>
  
  <pre><code>public LoginBean() {
  }
  
  public String doLogin() throws IOException, ServletException {
      ExternalContext context = FacesContext.getCurrentInstance()
              .getExternalContext();
  
      RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
              .getRequestDispatcher("/j_spring_security_check?j_username="
                      + userName + "&amp;j_password=" + password);
  
      // Forwards to original destination or to error page
      dispatcher.forward((ServletRequest) context.getRequest(),
              (ServletResponse) context.getResponse());
      FacesContext.getCurrentInstance().responseComplete();
  
      // It's OK to return null here because Faces is just going to exit.
      return null;
  }
  //get&amp;sets
  }
  </code></pre>