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 7031173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:46:05+00:00 2026-05-28T00:46:05+00:00

What configuration is needed to use annotations from javax.validation.constraints like @Size , @NotNull ,

  • 0

What configuration is needed to use annotations from javax.validation.constraints like @Size, @NotNull, etc.? Here’s my code:

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

public class Person {
      @NotNull
      private String id;

      @Size(max = 3)
      private String name;

      private int age;

      public Person(String id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
      }
}

When I try to use it in another class, validation doesn’t work (i.e. the object is created without error):

Person P = new Person(null, "Richard3", 8229));

Why doesn’t this apply constraints for id and name? What else do I need to do?

  • 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-28T00:46:06+00:00Added an answer on May 28, 2026 at 12:46 am

    For JSR-303 bean validation to work in Spring, you need several things:

    1. MVC namespace configuration for annotations: <mvc:annotation-driven />
    2. The JSR-303 spec JAR: validation-api-1.0.0.GA.jar (looks like you already have that)
    3. An implementation of the spec, such as Hibernate Validation, which appears to be the most commonly used example: hibernate-validator-4.1.0.Final.jar
    4. In the bean to be validated, validation annotations, either from the spec JAR or from the implementation JAR (which you have already done)
    5. In the handler you want to validate, annotate the object you want to validate with @Valid, and then include a BindingResult in the method signature to capture errors.

    Example:

    @RequestMapping("handler.do")
    public String myHandler(@Valid @ModelAttribute("form") SomeFormBean myForm, BindingResult result, Model model) {
        if(result.hasErrors()) {
          ...your error handling...
        } else {
          ...your non-error handling....
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What configuration values are needed to setup Log4j to use the following pattern? MyApp-Mon.log
In my current project we use some plugins needed by other plugins parameters like
I'd like to use Maven to include all the dependencies needed to run any
Is there some additional configuration needed before I can set thread priorities in a
Proxy configuration of a machine can be easily fetched using def check_proxy(): import urllib2
I use JAXB 2.1 to generate Java classes from several XSD files that I
I pass text strings from a configuration file into my Flex app, one of
Is it possible to use immutable types as configuration properties with .NET's configuration API?
I changed the configuration of the application and deployed the new code to production
Here is what I'm looking for: I'd like to separate pieces of functionality into

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.