简体   繁体   English

Spring Boot:创建名为“springSecurityFilterChain”的 bean 时出错

[英]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.

相关问题 Spring 安全性:创建名为 springsecurityfilterchain 的 bean 时出错 - Spring Security: error creating bean with name springsecurityfilterchain 创建名为“springSecurityFilterChain”的 bean 时出错 - Error creating bean with name 'springSecurityFilterChain' Spring MVC 安全性:创建名为“springSecurityFilterChain”的 bean 时出错 - Spring MVC Security: Error creating bean with name 'springSecurityFilterChain' OAUTH2 spring 创建名为“springSecurityFilterChain”的bean时出错 - OAUTH2 spring Error creating bean with name 'springSecurityFilterChain' 创建在WebSecurityConfiguration中定义的名称为'springSecurityFilterChain'的bean时出错 - Error creating bean with name 'springSecurityFilterChain' defined in WebSecurityConfiguration 无法修复创建名为“springSecurityFilterChain”的 bean 的错误 - Cannot fix the error creating bean with name 'springSecurityFilterChain' Spring 引导错误创建名称为错误的 bean - Spring boot Error creating bean with name Error 在实现 spring 安全性时,在类路径资源中创建名为“springSecurityFilterChain”的 bean 时出错 - Error creating bean with name 'springSecurityFilterChain' defined in class path resource while implementing spring security Spring Boot 错误创建名为“optionalLiveReloadServer”的bean - Spring Boot Error creating bean with name 'optionalLiveReloadServer' Spring Boot:创建名称为'methodValidationPostProcessor'的bean时出错 - Spring boot : Error creating bean with name 'methodValidationPostProcessor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM