小编Ent*_*ium的帖子

Spring Boot 2+ 无法自动装配。有不止一个 'UserDetailsS​​ervice' bean

大家好,我是春季安全和 jwt 的新手。我正在我的 spring boot 项目中实现 Jwt 以保护用户登录,我使用的是 spring boot 2.1.5,我对 spring boot 2+ 中的新 bean 限制知之甚少。我需要一些帮助..在这里我正在尝试@Autowired UserDetailsS​​ervice并且代码运行良好..结果也很好..但intellij在

@Autowired UserDetailsS​​ervice jwtUserDetailsS​​ervice

说......无法自动装配。有不止一种 UserDetailsS​​ervice 类型的 bean。

谁能解释一下这里发生了什么问题,为什么我不能自动装配以及为什么 Spring Boot 2+ 中的自动装配限制是什么?

并提前致谢

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurity extends WebSecurityConfigurerAdapter {

    @Autowired
    private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Autowired
    private JwtFilter jwtFilter;

    @Autowired
    private UserDetailsService jwtUserDetailsService; // here i got error only

    @Autowired
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(jwtUserDetailsService).passwordEncoder(passwordEncoder);
    }

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-security jwt spring-boot userdetailsservice

6
推荐指数
1
解决办法
5369
查看次数