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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:06:08+00:00 2026-05-24T21:06:08+00:00

Is it possible with JSR-303 bean validation to write a custom annotation that can

  • 0

Is it possible with JSR-303 bean validation to write a custom annotation that can talk to a back end service?

We accomplished this type of validation with the “old school” Spring validators. In that case, the validator was a Spring bean and could have other services injected into it. Then that validator is injected into the controller.

An example might be an annotation (perhaps @EmailExists) to verify if an email already exists. I can only do this with a SQL query using one of our services. I would prefer to “validate” this alongside the other annotations and check it as soon as possible and not have to explicity do it in a back end service.

NOTE: We are using iBatis/MyBatis so I can’t use any JPA/Hibernate tricks 🙂

thanks!

  • 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-24T21:06:09+00:00Added an answer on May 24, 2026 at 9:06 pm

    That’s definitely possible. Spring provides dependency injection support also within constraint validators. So you can simply inject any required services in your custom validators like this:

    public class EmailExistsValidator implements ConstraintValidator<EmailExists, String> {
    
        @Inject
        private EmailValidationService service;
    
        @Override
        public void initialize(EmailExists constraintAnnotation) {}
    
        @Override
        public boolean isValid(String value, ConstraintValidatorContext context) {
    
            if (value == null) {
                return true;
            }
    
            return service.exists(value);
        }
    }
    

    Depending on your concrete scenario it might be a good idea to first check “cheap” constraints such as @NotNull and only if these constraints are valid check more expensive constraints such as @EmailExists.

    You can do this with help of group sequences and a redefined default group sequence for your type.

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

Sidebar

Related Questions

Is it possible to validate a collection of objects in JSR 303 - Jave
Possible Duplicate: Symfony2 AJAX Login I have implemented a custom authentication handler service to
Possible Duplicate: How can I take screenshots with Perl? How can I take a
Possible Duplicates: ASP.NET- Sending an e-mail how to send mail using C#? How can
I have a host device that connects to anything running JSR-82. The problem is
Possible Duplicate: How can I combine multiple rows into a comma-delimited list in Oracle?
Hibernate's validator is my JSR-303 provider in my Spring MVC application. When I use
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: How can I increment a date by one day in Java? I
Possible Duplicate: C++ templates that accept only certain types For example, if we want

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.