简体   繁体   中英

Spring Boot: Error creating bean with name 'springSecurityFilterChain'

This is the error:

头像头像

When I use spring security in Spring Boot, I get an error. I've searched google, and read the Spring documentation, but I am still having trouble. I do not understand what this error means.

I would guess, that your instance of UserDetailsServiceImpl is null , based on what I see in your screenshot.

To really help you, please add the stacktrace. Not as a screenshot but textual.

我的绒球

我的网络安全配置

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

UserDetailsServicelmpl userDetailsService;


AuthEntryPointjwt unauthorizedHandler;

@Bean
public AuthTokenFilter authenticationJwtTokenFilter() {
    return new AuthTokenFilter();
}

@Override
public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
    authenticationManagerBuilder.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}

@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.cors().and().csrf().disable()
            .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
            .authorizeRequests().antMatchers("/api/auth/**").permitAll()
            .antMatchers("/api/test/**").permitAll()
            .anyRequest().authenticated();

    http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
}

用户详情服务实现

@Autowired UserRepository userRepository;

@Transactional
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userRepository.findByUsername(username)
            .orElseThrow(()->new UsernameNotFoundException("User not found with username"+ username));
    return  UserDetailslmpl.build(user);
}

用户详情服务

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM