Results 1 to 2 of 2

Thread: JSR303 bean method validation on non getter method?

Hybrid View

  1. #1

    Default JSR303 bean method validation on non getter method?

    I would like to use JSR 303 to validate beans in my application context. I have a small @Configuration that adds three beans:

    - LocalValidatorFactoryBean
    - BeanValidationPostProcessor
    - MySpecialBean

    MySpecialBean has one method: public @NotNull String getName() whose implementation always returns null. When I load the application context I get a validation error (as expected). However if I rename the method from getName() to name() the context starts normally (no error). As if the validation does not occur.

    I am using Spring 3.2.1 and Hibernate Validator 4.2.0. The documentation for HV suggests constraints can be added to any method (not just property getters). I am not sure why this isn't working.

    Does anyone know what is going on? Is there a configuration option I need to change?

  2. #2

    Default

    Turns out the solution is simple:

    - Add MethodValidationPostProcessor to the spring context.
    - Annotate type with @Validated

    Hope this helps someone as this doesn't appear to be documented.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •