title: Cannot fix the error creating bean with name 'springSecurityFilterChain'
body: <p>I've search in stackoverflow and many person got this error. I've tried all solution I got but no one works for me.
  Below, there is my files and the stacktraces :</p>
  <p>SecurityConfig.java</p>
  <pre><code>//Class contenant la configuration de la sécurité du projet
  @EnableWebSecurity
  @Configuration
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
      private UserDetailsService userDetailsService;
  
      @Bean(BeanIds.AUTHENTICATION_MANAGER)
      @Override
      public AuthenticationManager authenticationManagerBean() throws Exception {
          return super.authenticationManagerBean();
      }
  
      @Override
      public void configure(HttpSecurity httpSecurity) throws Exception {
          httpSecurity.csrf().disable()
                  .authorizeRequests()
                  .antMatchers(&quot;/api/v1/auth/**&quot;)
                  .permitAll()
                  .anyRequest()
                  .authenticated();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
          authenticationManagerBuilder.userDetailsService(userDetailsService)
                  .passwordEncoder(passwordEncoder());
      }
  
      @Bean
      PasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  }
  </code></pre>
  <p>UserDetailsService.java :</p>
  <pre><code>@Data
  @Builder
  public class UserDetailsService implements org.springframework.security.core.userdetails.UserDetails {
  
      private static final long serialVersionUID = 1L;
      Set&lt;GrantedAuthority&gt; authorities = null;
      private User user;
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          this.user = user;
      }
  
      public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {
          return authorities;
      }
  
      public void setAuthorities(Set&lt;GrantedAuthority&gt; authorities) {
          this.authorities = authorities;
      }
  
      public String getPassword() {
          return user.getPassword();
      }
  
      public String getUsername() {
          return user.getUsername();
      }
  
      public boolean isAccountNonExpired() {
          return false;
      }
  
      public boolean isAccountNonLocked() {
          return false;
      }
  
      public boolean isCredentialsNonExpired() {
          return false;
      }
  
      public boolean isEnabled() {
          return true;
      }
  }
  </code></pre>
  <p>UserDetailsServiceImpl.java</p>
  <pre><code>@Service
  @AllArgsConstructor
  public class UserDetailsServiceImpl implements UserDetailsService {
      private final UserRepository userRepository;
  
      @Override
      @Transactional(readOnly = true)
      public UserDetails loadUserByUsername(String username) {
          Optional&lt;User&gt; userOptional = userRepository.findByUsername(username);
          User user = userOptional
                  .orElseThrow(() -&gt; new UsernameNotFoundException(&quot;No user &quot; +
                          &quot;Found with username : &quot; + username));
  
          return new org.springframework.security
                  .core.userdetails.User(user.getUsername(), user.getPassword(),
                  user.isEnabled(), true, true,
                  true, getAuthorities(&quot;USER&quot;));
      }
  
      private Collection&lt;? extends GrantedAuthority&gt; getAuthorities(String role) {
          return singletonList(new SimpleGrantedAuthority(role));
      }
  }
  </code></pre>
  <p>Stacktrace :</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.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@5c3924fd of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.2.jar:5.3.2]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.2.jar:5.3.2]
  Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@5c3924fd of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider
      at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.2.jar:5.3.2]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.2.jar:5.3.2]
  Caused by: java.lang.RuntimeException: Could not postProcess org.springframework.security.authentication.dao.DaoAuthenticationProvider@7d7a8d23 of type class org.springframework.security.authentication.dao.DaoAuthenticationProvider
      at org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor.postProcess(AutowireBeanFactoryObjectPostProcessor.java:69) ~[spring-security-config-5.4.2.jar:5.4.2]
      at org.springframework.security.config.annotation.SecurityConfigurerAdapter$CompositeObjectPostProcessor.postProcess(SecurityConfigurerAdapter.java:118) ~[spring-security-config-5.4.2.jar:5.4.2]
      at org.springframework.security.config.annotation.SecurityConfigurerAdapter.postProcess(SecurityConfigurerAdapter.java:79) ~[spring-security-config-5.4.2.jar:5.4.2]
  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider@7d7a8d23': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: A UserDetailsService must be set
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.3.2.jar:5.3.2]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:420) ~[spring-beans-5.3.2.jar:5.3.2]
      at org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor.postProcess(AutowireBeanFactoryObjectPostProcessor.java:65) ~[spring-security-config-5.4.2.jar:5.4.2]
      ... 45 common frames omitted
  Caused by: java.lang.IllegalArgumentException: A UserDetailsService must be set
      at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.2.jar:5.3.2]
      at org.springframework.security.authentication.dao.DaoAuthenticationProvider.doAfterPropertiesSet(DaoAuthenticationProvider.java:85) ~[spring-security-core-5.4.2.jar:5.4.2]
      at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.afterPropertiesSet(AbstractUserDetailsAuthenticationProvider.java:119) ~[spring-security-core-5.4.2.jar:5.4.2]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.2.jar:5.3.2]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784) ~[spring-beans-5.3.2.jar:5.3.2]
  </code></pre>
  <p>There are many error here, but the main error i got here is the first. I've try to @Override the Security class and delete the inheritance WebSecurityConfigurerAdapter bhut it doesn't work.</p>