The org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
isn't getting injected. Not able to figure out the reason for this. Been through several questions both in and outside of stackoverflow, refining my searchquery everytime, just in the hope of finding a similar question posted by anyone.
Running the project in debug mode says Exception encountered during context initialization and then prints out below :
Application failed to start due to an exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' available: expected at least 1 bean which qualifies as autowire candidate.
Description:
Field encoder in com.codingethics.flightreservation.controller.UserController required a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder' in your configuration.
The error is quite obvious in its message, yet confusing because I've already made both the UserController class and the field encoder eligible for autowiring using required annotations. Moreover,here I'm trying to inject a dependency that's Spring provided, not user defined one. I'm not sure if anymore configuration is required. In this same project, I had successfully used JavaMailSender in a similar way.
So what's bothering me is why does this work ? :
@Component
public class EmailUtil {
@Autowired
private JavaMailSender javaMailSender;
}
but this doesn't : UserController.java
@Controller
public class UserController {
@Autowired
private BCryptPasswordEncoder encoder;
}
Any sort of help/guidance is highly appreciated.