title: Can't inject dependencies in Spring Security configuration
body: <p>I have a spring project using Spring Security. I want to inject dependencies into my WebSecurityConfigurerAdapter extending class but the dependencies do not seem to be getting injected. My controllers also use dependency injection and it does work there.</p>
  <p>My SecSecurity class:</p>
  <pre><code>@Configuration
  @Component
  @EnableWebSecurity
  public class SecSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      UserPrincipalDetailsService userPrincipalDetailsService;
      LogoutSuccessHandler handler = new LogoutSuccess();
  
  
  
      @Bean
      public PasswordEncoder passwordEncoder() {
          return new BCryptPasswordEncoder();
      }
  
      protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
         auth.authenticationProvider(authenticationProvider());
  
  
      }
  
  
      @Override
      protected void configure(final HttpSecurity http) throws Exception {
                http.   logout().and().
                        httpBasic()
                        .and()
                        .authorizeRequests()
                        .antMatchers( &quot;/&quot;, &quot;/home&quot;, &quot;/user&quot;, &quot;/vestigingen&quot;, &quot;/available&quot;, &quot;/logout&quot;).permitAll()
                        .anyRequest().authenticated()
                        .and().logout().logoutSuccessHandler(handler).deleteCookies(&quot;JSESSIONID&quot;).invalidateHttpSession(false).permitAll()
                        .and().csrf()
                        .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
  
  
      }
      @Bean
      public UserDetailsService userDetailsService() {
          return new UserPrincipalDetailsService();
      }
  
  
  
      DaoAuthenticationProvider authenticationProvider() {
          DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
          daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
          daoAuthenticationProvider.setUserDetailsService(this.userPrincipalDetailsService);
  
  
          return daoAuthenticationProvider;
      }
  
  }
  </code></pre>
  <p>It cannot find beans for the userPrincipalDetailsService class.</p>
  <p>UserPrincipalDetailService class:</p>
  <pre><code>@Component
  public class UserPrincipalDetailsService implements UserDetailsService {
      private UserRepositorySQL userRepository = new UserRepositorySQL();
  
      @Override
      public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
          UserEntity user = userRepository.findUserByUsername(s);
  
          UserPrincipal userPrincipal = new UserPrincipal(user);
  
          return userPrincipal;
      }
  }
  </code></pre>
  <p>to clarify: I can't inject any dependencies within my SecSecurityConfig class eventhough i have tried annotating it in many different ways.</p>