弹簧手动接线验证器错误

时间:2015-07-01 11:38:25

标签: spring

最初,我可以使用下面的自动装配代码获得成功的验证结果,但遇到以下错误,下面是新的手动接线代码。感谢是否有人可以告知这里有什么问题。

原始代码(正常工作):

@Autowired
@Qualifier("employeeFormValidator")  //Custom validator implement Spring Framework Validator class
private Validator validator;     // Spring Framework Validator class

@InitBinder
private void initBinder(WebDataBinder binder) {
    binder.setValidator(validator);
}

<beans:bean id="employeeFormValidator" class="com.project.spring.form.validator.EmployeeFormValidator" />

新代码(遇到错误):

  private EmployeeFormValidator employeeFormValidator;

    public void setEmployeeFormValidator(EmployeeFormValidator employeeFormValidator){
        this.employeeFormValidator = employeeFormValidator;
    }

    @InitBinder
    private void initBinder(WebDataBinder binder) {
        binder.setValidator(employeeFormValidator);
    }

    <beans:bean id="employeeFormValidator" class="com.project.spring.form.validator.EmployeeFormValidator" />
    <beans:bean id="employeeController" class="com.project.spring.form.controllers.EmployeeController">
        <beans:property name="employeeFormValidator" value="employeeFormValidator" />
    </beans:bean>

错误:

Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: 

Failed to convert property value of type 'java.lang.String' to required type 'com.project.spring.form.validator.EmployeeFormValidator' for property 'employeeFormValidator'; nested exception is java.lang.IllegalStateException: 

Cannot convert value of type [java.lang.String] to required type [com.project.spring.form.validator.EmployeeFormValidator] for property 'employeeFormValidator': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)

1 个答案:

答案 0 :(得分:1)

<beans:property name="employeeFormValidator" value="employeeFormValidator" />

应该是

<beans:property name="employeeFormValidator" ref="employeeFormValidator" />