どのように@Beanと@Autowired実際に動作しますか?

チャンドラ:

私の設定:

   @Autowired
    private PasswordEncoder passwordEncoder;

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

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

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

このコードは、罰金に動作します。私は削除する場合しかし@AutowiredからpasswordEncoder、私は追加する必要があります@Autowired上のconfigure方法。しかし、このルールはないに適用するauthenticationManagerBean()方法。誰も説明できますか?

Markovitz:

これを見てURL https://spring.io/guides/topicals/spring-security-architecture/ここは@BeanとしてあなたがAutowire AuthenticationManagerBuilder払いと思われます。

設定(AuthenticationManagerBuilder AUTH)には、このケースで動作し、passwordEncoderもAutowiredですので。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=188958&siteId=1