我試圖執行驗證像在Spring 3.0文檔的部分5.7.4.3描述我的web應用程序:春JSR303驗證不起作用像春天文檔中描述
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="webBindingInitializer">
<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="validator">
<bean class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
</property>
</bean>
</property>
</bean>
我添加的Hibernate驗證作爲依賴,一切看起來不錯,但開始我在下面的錯誤的Web應用程序的結果:
org.springframework.beans.NotWritablePropertyException:
Invalid property 'validator' of bean class
[org.springframework.web.bind.support.ConfigurableWebBindingInitializer]:
Bean property 'validator' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
當看它是很明顯,什麼是錯的API。 LocalValidatorFactoryBean
implements javax.validation.Validator
,而ConfigurableWebBindingInitializer.setValidator()
預計org.springframework.validation.Validator
。
任何解決方案?
編輯
This is the central class for
javax.validation
(JSR-303) setup in a Spring application context: It bootstraps ajavax.validation.ValidationFactory
and exposes it through the SpringValidator
interface as well as through the JSR-303Validator
interface and theValidatorFactory
interface itself.
像亞歷克斯·馬歇爾低於這個規定是不的情況。 LocalValidatorFactoryBean
只實現javax.validation.Validator
。
LocalValidatorFactoryBean
雖然延伸SpringValidatorAdapter
,它實現了org.springframework.validation.Validator
。
我也嘗試更新到'hibernate-core-3.5.0.Beta-1',但Spring的Hibernate代碼與此版本不兼容。 – Koraktor 2009-10-02 12:43:19
在http://jira.springframework.org/browse/SPR-6189上打開JIRA問題。 – Koraktor 2009-10-05 06:25:28