[英]Spring Boot: Error creating bean with name 'springSecurityFilterChain'
This is the error:这是错误:
When I use spring security in Spring Boot, I get an error.当我在 Spring Boot 中使用 spring security 时,出现错误。 I've searched google, and read the Spring documentation, but I am still having trouble.
我已经搜索过谷歌,并阅读了 Spring 文档,但我仍然遇到了问题。 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.根据我在屏幕截图中看到的内容,我猜测您的
UserDetailsServiceImpl
实例为null
。
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; @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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.