i have a problem with PasswordEncoder,
my code:
@Service
public class UserService {
private static final String DEFAULT_ROLE = "ROLE_USER";
private UserRepository userRepository;
private UserRoleRepository roleRepository;
public PasswordEncoder passwordEncoder;
@Autowired
public UserService(PasswordEncoder passwordEncoder){
this.passwordEncoder = passwordEncoder;
}
@Autowired
public void setUserRepository(UserRepository userRepository){
this.userRepository = userRepository;
}
@Autowired
public void setUserRoleRepository(UserRoleRepository roleRepository){
this.roleRepository = roleRepository;
}
public void addWithDefaultRole(User user){
UserRole defaultRole = roleRepository.findByRole(DEFAULT_ROLE);
user.getRoles().add(defaultRole);
String passwordHash = passwordEncoder.encode(user.getPassword());
user.setPassword(passwordHash);
userRepository.save(user);
}
}
error:
APPLICATION FAILED TO START
Description:
Parameter 0 of constructor in org.spring.service.UserService required a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.
Process finished with exit code 1
I don't know how to fix it.