Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:47:16+00:00 2026-06-02T12:47:16+00:00

Dear Spring community, What I am trying to implement is the following: I would

  • 0

Dear Spring community,

What I am trying to implement is the following:

  • I would like to have a custom validator per controller (via @InitBinder)
  • I would like Spring to call validator.validate() (so not this way)
  • I would like to use JSR-303 @Valid annotation for that
  • The bean to be validated (RegistrationForm) does not have any per-field JSR-303 annotations
  • I don’t want to include validation implementation (like Hibernate) into classpath; it will be useless as from above statement

I basically follow the steps mentioned here:

  • I add javax.validation.validation-api:validation-api as my dependency
  • I use <mvc:annotation-driven />
  • I mark my model with @Valid:
    public String onRegistrationFormSubmitted(@ModelAttribute("registrationForm") @Valid RegistrationForm registrationForm, BindingResult result) ...

So what happens, is that validation API tries to locate any implementation and fails:

Caused by: javax.validation.ValidationException: Unable to find a default provider
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:183)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)

The way out is to define a validator property for AnnotationDrivenBeanDefinitionParser:

<bean name="validator" class="org.company.module.RegistrationFormValidator" />

<mvc:annotation-driven validator="validator" />

but this approach means that the validator will be set to all controllers by ConfigurableWebBindingInitializer.initBinder().

I understand that I am trying to use the framework in a special way, but what the community will say, if there is a special meaning for validator property which tells that validator does not need to be resolved, e.g.

<mvc:annotation-driven validator="manual" />

with special treatment:

--- AnnotationDrivenBeanDefinitionParser.java.orig      2011-06-30 14:33:10.287577300 +0200
+++ AnnotationDrivenBeanDefinitionParser.java   2011-06-30 14:34:27.897449000 +0200
@@ -152,6 +152,10 @@

        private RuntimeBeanReference getValidator(Element element, Object source, ParserContext parserContext) {
                if (element.hasAttribute("validator")) {
+                       if ("manual".equals(element.getAttribute("validator"))) {
+                               return null;
+                       }
+
                        return new RuntimeBeanReference(element.getAttribute("validator"));
                }
                else if (jsr303Present) {

Any feedback is welcomed.

P.S. Repost from Spring Forum.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:47:17+00:00Added an answer on June 2, 2026 at 12:47 pm

    This is also a repost of my answer/workaround on the above mentioned forum. Anyway I think it might help having it here as well.

    The only workaround I found was to implement my own @Valid annotation, once Spring (at least in 3.1.1.RELEASE code base) only checks the method argument annotation’s simple name (please look into the org.springframework.web.method.annotation.ModelAttributeMethodProcessor class below). This way, I don’t need to add javax.validation.validation-api:validation-api to my project’s dependencies and I stop getting the infamous javax.validation.ValidationException: Unable to find a default provider.

    /**
     * Validate the model attribute if applicable.
     * <p>The default implementation checks for {@code @javax.validation.Valid}.
     * @param binder the DataBinder to be used
     * @param parameter the method parameter
     */
    protected void validateIfApplicable(WebDataBinder binder, MethodParameter parameter) {
        Annotation[] annotations = parameter.getParameterAnnotations();
        for (Annotation annot : annotations) {
            if (annot.annotationType().getSimpleName().startsWith("Valid")) {
                Object hints = AnnotationUtils.getValue(annot);
                binder.validate(hints instanceof Object[] ? (Object[]) hints : new Object[] {hints});
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear All, I have 2 input string 1)stack,over,flow 2)stack/over,flow,com I would like to print
Dear g++ hackers, I have the following question. When some data of an object
I have the following string and regex: var string = Dear [to name], [your
Dear fellow programmers, I am working on my B&B's website www.bordemundo.com and would like
dear all, i have a string like this, ...1name: john, 2name: lice, 3name: mike....
Dear Scholars I am trying to parse a RSS feed with the following item
dear community of professional developers! I'm trying to figure out how to make a
Dear Stack Overflow Community, I have a question regarding how to incorporate a WHERE
Dear Android hackers, I am trying to do the following in my Android App:
Dear all, I have a question about Facebook Page: ( NOT user profile page,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.