[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

找不到PasswordEncoder的Bean #35

Closed
zhongmax opened this issue Apr 24, 2020 · 3 comments
Closed

找不到PasswordEncoder的Bean #35

zhongmax opened this issue Apr 24, 2020 · 3 comments

Comments

@zhongmax
Copy link
zhongmax commented Apr 24, 2020

在mall整合SpringSecurity和JWT实现认证和授权(二)中

Field passwordEncoder in com.csmaxwell.mall.service.impl.UmsAdminServiceImpl required a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.

在 UmsAdminServiceImpl 的

@Autowired
private PasswordEncoder passwordEncoder

这个Bean不是在 SecurityConfig中添加了吗?为什么会提示找不到呢?

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Autowired
    private UmsAdminService adminService;
    @Autowired
    private RestfulAccessDeniedHandler restfulAccessDeniedHandler;
    @Autowired
    private RestAuthenticationEntryPoint restAuthenticationEntryPoint;

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        ...
    }

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

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

使用源代码可以运行,我一一对比,发现只有一个地方不同:
这是作者的源代码 Security 的版本

这是我使用的 Security 版本

作者使用的是 2.1.3.RELEASE
是因为spring-boot-starter-security的版本不一样的原因吗?
希望能有大佬帮我解惑一下
--更新--
我把作者源代码更新到 2.1.13.RELEASE 现在版本一致,还是作者的代码可以运行,而我的一直说找不着这个 Bean,不要@Autowired注解,可以运行,但是链接都指向的 localhost:8080/login。
把作者的 passwordEncoder 方法上面的@bean去掉,报的错误就是一样的,所有是Spring没有找到这个Bean吗?

@zhongmax
Copy link
Author

重新新建一个项目,把代码复制进去,又没有报错了,不清楚什么原因...

@RockFade
Copy link

老哥这个问题怎么解决的 我也遇到了

@swordmagic
Copy link

俺也遇到了..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants