类型没有合格豆“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”可用

Pariskrit A. Moktan:

我使用BCryptPasswordEncoder编码了密码,但是当我使用它的编码功能在我保存在UserService类的功能它给了我这个错误编码的密码:

错误创建名为“UserController的”豆:通过现场“userServiceInter”表示不满意的依赖; 嵌套的例外是org.springframework.beans.factory.UnsatisfiedDependencyException:错误创建名为“userService”豆:通过现场“地下室”表示不满意的依赖; 嵌套的例外是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有合格类型的豆“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”可供选择:预计将有至少1 Bean上有资格作为自动装配候选人。依赖注解:{@ org.springframework.beans.factory.annotation.Autowired(所需=真)}

当我删除此它的工作原理,但密码不编码。

UserService类:

   @Service
   public class UserService implements UserServiceInterface{

@Autowired
UserRepository repo;

@Autowired
BCryptPasswordEncoder crypt;

@Autowired
RoleRepository roleRepo;

public void save(User user) {


        user.setPassword(crypt.encode(user.getPassword()));
        Role role = roleRepo.findByRole("USER");
        user.setRoles(new HashSet<Role>(Arrays.asList(role)));
        repo.save(user);


   }

@Override
public User findByUsername(String userName) {

    User user = repo.findByUserName(userName);
    return user;

}

    }

UserServiceInterface:

   @Service
    public interface UserServiceInterface {


public void save(User user);

public User findByUsername(String userName);

    }

SecurityConfiguration:

   @Configuration
   @EnableWebSecurity
    public class SecurityConfiguration extends 
   WebSecurityConfigurerAdapter {

@Autowired
UserPrincipleDetailsService user;

@Autowired
private SimpleAuthenticationSuccessHandler successHandler;

@Override
protected void configure(AuthenticationManagerBuilder auth) throws 
    Exception {

    auth.authenticationProvider(daoAuthenticationProvider());


}

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests()

        .antMatchers("/assets/css/**").permitAll()
        .antMatchers("/img/**").permitAll()
        .antMatchers("/home").permitAll()
        .antMatchers("/register/**").permitAll()
        .antMatchers("/registerUser").permitAll()
        .antMatchers("/admin/**").hasRole("ADMIN")
        .antMatchers("/user/**").hasAnyRole("ADMIN","USER")
        .anyRequest().authenticated()
        .and()
        .csrf().disable()
        .formLogin()
        .successHandler(successHandler)
        .loginPage("/home").permitAll()
        .loginProcessingUrl("/signin")
        .failureUrl("/home?error=true")


        .and()
        .logout().logoutRequestMatcher(new 
    AntPathRequestMatcher("/logout"))
        .logoutSuccessUrl("/home")
        .and()
        .exceptionHandling().accessDeniedPage("/home");

}

@Bean
DaoAuthenticationProvider daoAuthenticationProvider() {

    DaoAuthenticationProvider dao = new 
    DaoAuthenticationProvider();
    dao.setPasswordEncoder(passwordEncoder());
    dao.setUserDetailsService(user);

    return dao;


}

@Bean
PasswordEncoder passwordEncoder() {

    return new BCryptPasswordEncoder();
}

}
SHAILESH钱德拉:

更改

@Autowired
BCryptPasswordEncoder crypt;

@Autowired
PasswordEncoder crypt

或变化的PasswordEncoder方法

@Bean
BCryptPasswordEncoder passwordEncoder() {

    return new BCryptPasswordEncoder();
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型“org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”的豆不能被发现

考虑在配置中定义类型为“ org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder”的bean

NoSuchBeanDefinitionException:没有可用的'org.springframework.boot.web.reactive.error.ErrorAttributes'类型的合格bean:

无法自动连线栏位:专用org.springframework.security.crypto.password.PasswordEncoder;

没有可用的“org.springframework.batch.core.Job”类型的合格 bean:预期单个匹配 bean,但发现 2:

类型没有合格豆“repository.Dao”可用

类型没有合格豆“repository.PersonRepository”可用

春天开机测试“没有合格可用类型的豆”

无法安装golang.org/x/crypto/bcrypt

Spring Security BCryptPasswordEncoder:編碼後的密碼看起來不像使用相同密碼的 BCrypt

导入org.springframework.security无法解析

春季启动错误没有合格类型的豆“javax.persistence.EntityManagerFactory”可用

需要类型为org.springframework.security.authentication.AuthenticationManager的bean

春季安全性:NoSuchBeanDefinitionException:找不到类型为[org.springframework.security.config.annotation.ObjectPostProcessor]的合格Bean

没有定义类型为[org.springframework.transaction.PlatformTransactionManager]的合格Bean

引起原因:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有合格的类型的bean

没有类型为'org.springframework.jdbc.core.JdbcTemplate'的合格bean错误

没有类型为'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder'的合格bean

没有类型为org.springframework.jdbc.core.JdbcTemplate的合格bean

没有'org.springframework.mail.javamail.JavaMailSender'类型的合格bean - Spring MVC

BCrypt:具有Spring Security的空编码密码

react native - 使用带有 JWS、bcrypt 或 react-native-crypto 的数字签名验证源

org.springframework.security.core.userdetails.UserDetails 创建用户

缺少org.springframework.security.config软件包

坚持org.springframework.security.core.userdetails.User或UserDetails

java.lang.NoClassDefFoundError:org / springframework / security / authentication / AuthenticationManager

org.springframework.security.oauth2.provider.endpoint.TokenEndpoint handleException

没有可用的'ThreadPoolTaskExecutor'类型的合格bean

没有可用的[…]类型的合格Bean