Добрый день. Пытаюсь разобраться с Spring Security. Выскакивает такой Exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerDetailsServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private ua.kiev.izodrom.egorov.implementServices.CustomerServiceImplement ua.kiev.izodrom.egorov.detailServices.CustomerDetailsServiceImpl.service;
AppConfig:
@Configuration
@PropertySource("classpath:config.properties")
@EnableTransactionManagement
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
@Bean
public UserDetailsService userDetailsService(){
return new CustomerDetailsServiceImpl();
}
}
SecurityConfig:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService service;
@Autowired
public void registerGlobalAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(service)
.passwordEncoder(getShaPasswordEncoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.exceptionHandling().accessDeniedPage("/unauthorized")
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/j_spring_security_check")
.failureUrl("/login?error")
.usernameParameter("j_login")
.passwordParameter("j_password")
.permitAll()
.and()
.logout()
.permitAll()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?logout")
.invalidateHttpSession(true);
}
@Bean
public ShaPasswordEncoder getShaPasswordEncoder(){
return new ShaPasswordEncoder();
}
}
CustomerDetailsServiceImpl:
@Service
public class CustomerDetailsServiceImpl implements UserDetailsService {
@Autowired
private CustomerServiceImplement service;
@Override
public UserDetails loadUserByUsername(String var1) throws UsernameNotFoundException {
Customer customer = service.getCustomerByLogin(var1);
System.out.println("UserDetailsImpl "+customer.getLogin()+" "+customer.getPassword()+" "+customer.getRole());
if (customer == null)
throw new UsernameNotFoundException(var1 + " not found");
Set<GrantedAuthority> roles = new HashSet<>();
roles.add(new SimpleGrantedAuthority(customer.getRole().name()));
return new User(customer.getLogin(), customer.getPassword(), roles);
}
}