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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:48:46+00:00 2026-05-31T23:48:46+00:00

I was trying to create Hibernate Validator bean, and run into this problem creating

  • 0

I was trying to create Hibernate Validator bean, and run into this problem creating a bean from static factory method in another Class. I found a Spring way to get my Validator bean initialized (solution at the bottom), but the problem itself remains unsolved. Validator is used as example case here.

This is how I create the Validator instance in Java

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();

This is how I tried to create the bean in applicationContext.xml

<bean id="validatorFactory" 
    class="javax.validation.ValidatorFactory" 
    factory-method="javax.validation.Validation.buildDefaultValidatorFactory" />

<bean id="validator" 
    class="javax.validation.Validator" 
    factory-bean="validatorFactory"
    factory-method="getValidator" />

What I understand is that in “factory-method” you can only access static methods defined in the Class defined in the “class” parameter. Since the method buildDefaultValidatorFactory() is static I cant create a instance of Validation and give it as “factory-bean” for the validatorFactory like this:

<bean id="validation" class="javax.validation.Validation" />

<bean id="validatorFactory" 
    class="javax.validation.ValidatorFactory" 
    factory-bean="validation"
    factory-method="buildDefaultValidatorFactory" />

This ends up to error message

“Check that a method with the specified name exists and that it is non-static“

Question is how would you create bean in this kind of a situation in Spring?

This is how I solved the Validator problem:

<bean id="validator"
  class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
  • 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-31T23:48:47+00:00Added an answer on May 31, 2026 at 11:48 pm

    The factory-method should only contain the method name, not including the class name.

    If you want to use a static factory, give the class of the factory(!) to the bean declaration, if you want to use an instance factory, give the factory-bean to the bean declaration, but don’t give both: The class of the created bean is not given in the bean declaration.

    So a full example should look like this, using a static factory for validatorFactory and an instance factory for validator:

    <bean id="validatorFactory" 
        class="javax.validation.Validation" 
        factory-method="buildDefaultValidatorFactory" />
    
    <bean id="validator" 
        factory-bean="validatorFactory"
        factory-method="getValidator" />
    

    See details on the documentation:

    http://static.springsource.org/spring/docs/2.0.x/reference/beans.html#beans-factory-class-static-factory-method

    To answer you question – How would you create bean in this kind of a situation in Spring? – Do it exactly as shown here, or if you can, use a utility class like the LocalValidatorFactoryBean, which simplifies the Spring configuration.

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

Sidebar

Related Questions

I am trying to create a Eclipse project from Hibernate tutorials under path \hibernate-distribution-3.5.3-Final\project\tutorials\eg
I'm trying to run a simple Hibernate application, but I get this error: org.hibernate.exception.SQLGrammarException:
I'm using Hibernate validator and trying to create a little util class: public class
I am trying to create entity classes from database for my JPA/Hibernate project in
I'm trying to create a web application using maven, tomcat and hibernate. Now I'm
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
I am trying to create an index on a particular text string using Hibernate
I am trying to create a menu. And, for some reason I get org.hibernate.exception.GenericJDBCException:
I'm trying to localize error messages from NHibernate.Validator. From what I have read, the
I am trying to create a my first hibernate application in these application by

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.