title: Spring injection of userdetailsservice in security config class fails
body: <p>I am new to spring security and i am trying to configure it using java but when i try to inject a UserDetailsService into a security config class i get a 404 error page but when i inject it into a controller the injection works. am using spring version 4.1.6 and spring security 4.0.0</p>
  
  <p>here is my security config class</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
  @Autowired
  @Qualifier("loginService")
  UserDetailsService loginService; //THIS IS THE POINT OF FAILURE
  
  @Override
  protected void configure(HttpSecurity http) throws Exception {
      http
      .csrf().disable()
          .authorizeRequests()
              .antMatchers("/").permitAll()
              .anyRequest().authenticated()
              .and()
          .formLogin()
              .loginPage("/")
              .usernameParameter("username")
              .passwordParameter("password")
              .defaultSuccessUrl("/userlist")
              .failureUrl("/")
              .permitAll()
              .and()
          .logout()
              .permitAll();
  }
  
  @Autowired
  public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
      /*auth
          .inMemoryAuthentication()
              .withUser("user").password("password").roles("USER");*/
      auth.userDetailsService(loginService).passwordEncoder(passwordEncoder());
  }
  
  @Override
  public void configure(WebSecurity web) throws Exception {
  
              web
                .ignoring()
                   .antMatchers("/resources/**");
  
            }
  
  
  @Bean
  public Md5PasswordEncoder passwordEncoder(){
      Md5PasswordEncoder encoder = new Md5PasswordEncoder();
      return encoder;
  }
  } 
  </code></pre>
  
  <p>This is the UserDetailsService class</p>
  
  <pre><code>@Service("loginService")
  public class LoginService implements UserDetailsService{
  
  @Autowired
  UserRepository userRepository;
  
  @Transactional
  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
  
      SiteUser user = userRepository.findByUsername(username);
  
      Collection&lt;SimpleGrantedAuthority&gt; authorities = new ArrayList&lt;SimpleGrantedAuthority&gt;();
       SimpleGrantedAuthority userAuthority = new SimpleGrantedAuthority("ROLE_USER");
       SimpleGrantedAuthority adminAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
      User u = null;
      if(user == null) 
          throw new UsernameNotFoundException("No such User: " + username);
      else
      {
  
          if (user.getRole().equals("USER"))
                 authorities.add(userAuthority);
  
          else if (user.getRole().equals("ADMIN")) 
          {
                 authorities.add(userAuthority);
                 authorities.add(adminAuthority);
          }
          u = new User(user.getUsername(), user.getPassword(), authorities);
      }
  
      return u;
  }
  
  }
  </code></pre>
  
  <p>The rest of the project is available
  <a href="https://github.com/vinnieashken/Test/" rel="nofollow">here</a></p>