Spring Framework
  1. Spring Framework
  2. SPR-6189

LocalValidatorFactoryBean doesn't implement org.springframework.validation.Validator

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 3.0 M1, 3.0 M2, 3.0 M3, 3.0 M4, 3.0 RC1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      LocalValidatorFactoryBean does not implement the org.springframework.validation.Validator interface.
      The validation configuration as described in Section 5.7.4.3 thus results in the following error on startup:

      Caused by: 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?
              at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:850)
              at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:701)
              at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:78)
              at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:60)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
              ... 52 more
      

      Using the same configuration as in the example:

      <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
          <property name="webBindingInitializer">
              <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                  <property name="validator" ref="validator" />
              </bean>
          </property>
      </bean>
      
      <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
      

      Hibernate Validator is in the classpath.

        Activity

        Hide
        Sebastian Staudt added a comment -

        As LocalValidatorFactoryBean extends SpringValidatorAdapter the following workaroung can be used for the "validator" bean above.

        <code>
        @Autowired
        private Validator validator;

        @InitBinder
        protected void initBinder(WebDataBinder binder)

        { binder.setValidator((org.springframework.validation.Validator) this.validator); }

        <code>

        This has to be done in each controller using JSR-303 validation.

        Show
        Sebastian Staudt added a comment - As LocalValidatorFactoryBean extends SpringValidatorAdapter the following workaroung can be used for the "validator" bean above. <code> @Autowired private Validator validator; @InitBinder protected void initBinder(WebDataBinder binder) { binder.setValidator((org.springframework.validation.Validator) this.validator); } <code> This has to be done in each controller using JSR-303 validation.
        Hide
        Juergen Hoeller added a comment -

        Well, LocalValidatorFactoryBean does implement the org.springframework.validation.Validator interface - exactly through inheriting from SpringValidatorAdapter. Or am I missing something here?

        The exception above rather seems to indicate that the setValidator method on ConfigurableWebBindingInitializer isn't found for some reason...

        Juergen

        Show
        Juergen Hoeller added a comment - Well, LocalValidatorFactoryBean does implement the org.springframework.validation.Validator interface - exactly through inheriting from SpringValidatorAdapter. Or am I missing something here? The exception above rather seems to indicate that the setValidator method on ConfigurableWebBindingInitializer isn't found for some reason... Juergen

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Sebastian Staudt
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              4 years, 28 weeks, 1 day ago

              Time Tracking

              Estimated:
              Original Estimate - 2d
              2d
              Remaining:
              Remaining Estimate - 2d
              2d
              Logged:
              Time Spent - Not Specified
              Not Specified