title: Error creating bean with name 'springSecurityFilterChain' defined in class path resource while implementing spring security
body: <p>I've been trying to implement Spring security for LDAP Authentication in Java and I'm stuck here where it's not able to find bean of 'springSecurityFilterChain'.
  Following is the error -</p>
  <p>I'm getting following error -</p>
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error 
  
  creating bean with name 'springSecurityFilterChain' defined in class 
  path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: 
  Bean instantiation via factory method failed; 
  nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 
  'springSecurityFilterChain' threw exception; nested exception is java.lang.NoClassDefFoundError:
  </code></pre>
  <p>I tried to google a lot about it, got to know a few things but not sure how to implement that.
  Here - <a href="https://docs.spring.io/spring-security/site/docs/4.2.x/reference/html/jc.html" rel="nofollow noreferrer">https://docs.spring.io/spring-security/site/docs/4.2.x/reference/html/jc.html</a>
  it says to implement following peace of code which will register this bean in Spring but not sure where exactly to put it.</p>
  <pre><code>public class SecurityWebApplicationInitializer
      extends AbstractSecurityWebApplicationInitializer {
      public SecurityWebApplicationInitializer() {
          super(WebSecurityConfig.class);
      }
  }
  </code></pre>
  <p>Also, this is config file where I'm trying to implement Spring security</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  @Import({ WebSecurityConfiguration.class })
  @EnableGlobalAuthentication
  @Import({ SecurityConfig.class})
  public class LdapSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
          successHandler.setAlwaysUseDefaultTargetUrl(true);
          successHandler.setTargetUrlParameter(&quot;/&quot;);
          http
          .requiresChannel().anyRequest().requiresInsecure().and()
              .authorizeRequests()
                  .anyRequest().permitAll()
                  .and()
              .formLogin()
              .loginPage(&quot;/login_form&quot;)
              .loginProcessingUrl(&quot;/login&quot;)
              .successHandler(successHandler)
              .failureUrl(&quot;/login_form?error&quot;)
              .and()
              .logout().logoutSuccessUrl(&quot;/login_form&quot;)
              .and()
              .csrf().disable();
          //http.addFilterBefore(new AuthTokenFilter(authenticationManager(), userDao), BasicAuthenticationFilter.class);
          http.sessionManagement().maximumSessions(2).expiredUrl(&quot;/login_form&quot;);
      }
  
      @Override
      public void configure(AuthenticationManagerBuilder auth) throws Exception {
          LdapAuthenticationProviderConfigurer ldapConfig =
                  auth.ldapAuthentication();
          ldapConfig.contextSource().url(&quot;ldap://ldap.vmware.com&quot;);
      
          ldapConfig.contextSource().managerDn(&quot;x&quot;);
          ldapConfig.contextSource().managerPassword(&quot;y&quot;);
          ldapConfig.userSearchFilter(&quot;(sAMAccountName={0})&quot;);
          ldapConfig.userSearchBase(&quot;dc=z, dc=com&quot;);
          ldapConfig.groupSearchBase(null);
          TokenAuthProvider provider = new TokenAuthProvider();
          auth.authenticationProvider(provider);
      }
  }
  </code></pre>
  <p>Please giude me through!</p>