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

  • Home
  • SEARCH
  • 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 4110870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:59:26+00:00 2026-05-20T21:59:26+00:00

I have problem using annotated validation in spring 3 mvc. I´m not sure if

  • 0

I have problem using annotated validation in spring 3 mvc. I´m not sure if the problems is in validation or Spring´s capability to bind validation errors to BindingResult object.

Here is my Controller’s method

@RequestMapping(value = "/test", method = RequestMethod.POST)
public String testingValidation(@Valid Test test,BindingResult result){

    if(result.hasErrors()){
        logger.debug("Error in validation "+result.toString());
        return "redirect:http://someWrongPlace.com";
    }

    logger.debug("No validation error "+result.toString());
    return "redirect:http://theRightPlace.com";
}

And here´s my form object

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

public class Test {


   @NotNull
   @Size(min = 5)
   private String text;

   public String getText() {
    return text;
   }

   public void setText(String text) {
    this.text = text;
   }
}

Here´s a part of my appContext (and yes.. Everything else works fine)

   <?xml version="1.0" encoding="UTF-8"?>
   <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:amq="http://activemq.apache.org/schema/core"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd    
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://activemq.apache.org/schema/core 
    http://activemq.apache.org/schema/core/activemq-core.xsd
    http://www.springframework.org/schema/jms 
    http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"
    default-autowire="byName">

    <mvc:annotation-driven/>

    <context:annotation-config/>

I have Hibernate Validator and Validation API in my classpath

   <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>com.springsource.org.hibernate.validator</artifactId>
        <version>4.0.2.GA</version>
    </dependency>

Problem is that i can call this test-method with valid url (“/test?test=thisIsValidInput”) and with invalid url (“/test?test=a”). Both of the times BindingResult object has no errors.
EDITED:
I think i have the JSR-303 Validator provider in my classpath. I also have been able to run Junit test to my validator constraints. If the Validator loading is done differently in Spring, can someone explain it? Below is my Junit test.

private static Validator validator;

   Test test;

@Before
public void setUp(){

    ValidatorFactory factory=Validation.buildDefaultValidatorFactory();
    this.validator=factory.getValidator();
    test = new Test();
}


@Test
public void testTextIsNotNull(){

    test.setText("");

    Set<ConstraintViolation<Test>>errors = validator.validate(message);
    Assert.assertEquals(1, errors.size());
    logger.debug(errors.toString());
}

In console it says:

         INFO [main] (Version.java:56) Hibernate Validator 4.0.2.GA 
         DEBUG [main](ResourceBundleMessageInterpolator.java:193)ValidationMessages
         not found. Delegating to org.hibernate.validator.ValidationMessages 
         DEBUG [main]defaultTraversableResolver.java:71)Cannot find 
         javax.persistence.PersistenceUtil on classpath. All properties will per 
         default be traversable. 
         DEBUG [main] (ValidationXmlParser.java:218) No META-INF/validation.xml found.
         Using annotation based configuration only
  • 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-05-20T21:59:29+00:00Added an answer on May 20, 2026 at 9:59 pm

    For this to work an implementation of the jsr 303 provider (hibernate validator for eg) needs to be present on your classpath. It is automatically picked up by spring if one exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem using Linq to NHibernate to load an object and eagerly
I have problem using arabic font for iOS. All fonts have the same render,
i have problem using LIKE structure in DB2 : for example: select * from
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem using a local SQL Server CE database with C# and
I have a problem using the SSIS. I try to import data from database
I have a problem using JSON and arrays. Here is my code: while($row =
i have a problem using the Catch Clipboard Events code found on this link
I have a problem using the string function erase with iterators. The function below
I have a problem using a simple AppleScript on Mac OSX 10.7.3. With the

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.