Проверка Spring JSR303 не работает как описанный в Документации Spring

Netbeans 6.5 имеет улучшенный импорт проекта Eclipse, который, как предполагается, синхронизирует изменения от Netbeans назад к Eclipse: http://wiki.netbeans.org/NewAndNoteWorthyNB65#section-NewAndNoteWorthyNB65-EclipseProjectImportAndSynchronization

6
задан skaffman 21 December 2009 в 08:44
поделиться

2 ответа

Вот способ решения этой проблемы:

Используя конфигурацию bean-компонента валидатора из моего вопроса выше, вы должны добавить следующий код в каждый контроллер, используя проверку.

@Autowired
private javax.validation.Validator validator;

@InitBinder
protected void initBinder(WebDataBinder binder) {
    binder.setValidator((org.springframework.validation.Validator) this.validator);
}

Это грязно, но работает, потому что LocalValidatorFactoryBean расширяет SpringValidatorAdapter и реализует org.springframework.validation.Validator .

6
ответ дан 10 December 2019 в 00:41
поделиться

If you look at the Javadocs for ConfigurableWebBindingInitializer, its property 'validator' is of type 'org.springframework.validation.Validator'. If you then look at the Javadocs for LocalValidatorFactoryBean, you'll see that it actually implements neither FactoryBean (to create an org.springframework.validation.Validator) nor does it implement org.springframework.validation.Validator itself, so the bean you're giving the 'validator' property of ConfigurableWebBindingInitializer is of the wrong type, as indicated by the error. I suspect this is a (gross?) oversight on the part of the Spring developers, and you should create an issue for this in their JIRA issue tracker at jira.springframework.org

4
ответ дан 10 December 2019 в 00:41
поделиться
Другие вопросы по тегам:

Похожие вопросы: