'No qualifying bean of type ... Validator question
the error in question is
No qualifying bean of type
'com.brandedCompany.validator.CustomerLoginValidator' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.brandedCompany.validator.CustomerLoginValidator' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
The code execution order is
CustomerLoginController -> CustomerLoginValidator -> CustomerValidator .
Here is the executable code.
First, the "CustomerLoginController ."
@Controller
@RequestMapping("/login")
public class CustomerLoginController {
final Logger logger =
LoggerFactory.getLogger(CustomerLoginController.class);
@Autowired
// customer login validator
private CustomerLoginValidator customerLoginValidator;
public CustomerLoginController(CustomerLoginValidator customerLoginValidator) {
this.customerLoginValidator = customerLoginValidator;
}
public class CustomerLoginValidator implements Validator {
final Logger logger = LoggerFactory.getLogger(CustomerValidator.class);
@Autowired
private CustomerValidator customerValidator;
public class CustomerValidator implements Validator {
final Logger logger = LoggerFactory.getLogger(CustomerValidator.class);
@Autowired
private CRUDService crudService;
Here is the servlet-context.xml :
<context:component-scan base-package="com.brandedCompany"/>
<!-- <view-controller path="/" view-name="login"/>-->
<annotation-driven validator="employeeLoginValidator"/>
<beans:bean id="employeeLoginValidator" class="com.brandedCompany.validator.EmployeeLoginValidator"/>
<annotation-driven validator="employeeValidator"/>
<beans:bean id="employeeValidator" class="com.brandedCompany.validator.EmployeeValidator"/>
<annotation-driven validator="customerLoginValidator"/>
<beans:bean id="customerLoginValidator" class="com.brandedCompany.validator.CustomerLoginValidator"/>
<annotation-driven validator="customerValidator"/>
<beans:bean id="customerValidator" class="com.brandedCompany.validator.CustomerValidator"/>
Here is the root-context.xml code. The state registered as a bean is correct and I do not know why it is not automatically injected.
<tx:annotation-driven/>
<context:component-scan base-package="com.brandedCompany"/>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
