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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:11:53+00:00 2026-06-05T13:11:53+00:00

I have a REST service project integrated with spring. I am trying to integrate

  • 0

I have a REST service project integrated with spring. I am trying to integrate bean validation. I have made a custom annotation:

 /**
  * Denotes a field as being no empty.
  *
  * @author pguzun
  */
 @Target({METHOD, FIELD, ANNOTATION_TYPE})
 @Retention(RUNTIME)
 @Constraint(validatedBy = {INotEmptyValidator.class})
 public @interface NotEmpty {

    Error error() default Error.ServerError;

    String message() default "{error.notEmpty}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};
}

With

@Constraint(validatedBy = {INotEmptyValidator.class})

I specified the validator interface.

This is the validator implementation.

 /**
  * Checks that a String is not empty.
  *
  * @see StringUtils#isEmpty(java.lang.CharSequence)
  * @author pguzun
  */
@Component
public class NotEmptyValidatorImpl implements INotEmptyValidator {


 @Override
 public void initialize(NotEmpty notEmpty) {
     // NOTHING TO DO
 }

 @Override
 public boolean isValid(String value, ConstraintValidatorContext context) {
     return !StringUtils.isEmpty(value);
 }
}

I did make a custom Validator Constraint Factory

    /**
    * Is custom an {@link ConstraintValidatorFactory }. Engine for defining factory
    * methods for {@link ConstraintValidator}'s.
    *
    * @author pguzun
    */
    public class NeoSpringConstraintValidatorFactory implements ConstraintValidatorFactory, ApplicationContextAware {

        private ApplicationContext applicationContext;

        public NeoSpringConstraintValidatorFactory() {
        }

        @Override
        public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
            Map<String, T> beansByNames = applicationContext.getBeansOfType(key);
            if (beansByNames.isEmpty()) {
                try {
                    return key.newInstance();
                } catch (InstantiationException e) {
                    throw new RuntimeException("Could not instantiate constraint validator class '" + key.getName() + "'", e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Could not instantiate constraint validator class '" + key.getName() + "'", e);
                }
            }
            if (beansByNames.size() > 1) {
                throw new RuntimeException("Only one bean of type '" + key.getName() + "' is allowed in the application context");
            }
            return (T) beansByNames.values().iterator().next();
        }

        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            Assert.notNull(applicationContext, "applicationContext can not be null");
            this.applicationContext = applicationContext;
        }
    }

and configured it like this

<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" >
    <property name="constraintValidatorFactory" ref="constraintValidatorFactory"/> 
</bean>
<bean id="constraintValidatorFactory" class="com...NeoSpringConstraintValidatorFactory" >
</bean>

When I invoke validate in service on a bean that has a field annotated like this

/**
* The User's value object definition
*
* @author pguzun
*/
@XmlRootElement()
@XmlAccessorType(XmlAccessType.FIELD)
public class UserVO {

    @XmlElement
    private long id;
    @NotEmpty(error = Error.EmailVoid)
    private String email;   

I get

    SEVERE: Servlet.service() for servlet jersey-serlvet threw exception
    javax.validation.ValidationException: HV000032: Unable to initialize com.backend.rest.validation.validator.NotEmptyValidatorImpl.
        at org.hibernate.validator.internal.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:450)
        at org.hibernate.validator.internal.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:352)
        at org.hibernate.validator.internal.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:334)
        at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:155)
        at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:125)
        at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:86)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:442)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:387)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:351)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:303)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)
        at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:194)
        at com.backend.rest.UserResourceImpl.validateGuest(UserResourceImpl.java:100)
        at com.backend.rest.UserResourceImpl.register(UserResourceImpl.java:77)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
        at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
        at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
        at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
        at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.ClassCastException: $Proxy84 cannot be cast to com.backend.rest.validation.validator.NotEmpty
        at com.backend.rest.validation.validator.NotEmptyValidatorImpl.initialize(NotEmptyValidatorImpl.java:18)
        at org.hibernate.validator.internal.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:447)
        ... 49 more
    Jun 4, 2012 1:36:57 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jersey-serlvet threw exception
    javax.validation.ValidationException: HV000032: Unable to initialize com.backend.rest.validation.validator.NotEmptyValidatorImpl.
        at org.hibernate.validator.internal.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:450)
        at org.hibernate.validator.internal.engine.ConstraintTree.createAndInitializeValidator(ConstraintTree.java:352)
        at org.hibernate.validator.internal.engine.ConstraintTree.getInitializedValidator(ConstraintTree.java:334)
        at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:155)
        at org.hibernate.validator.internal.engine.ConstraintTree.validateConstraints(ConstraintTree.java:125)
        at org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:86)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:442)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:387)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:351)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:303)
        at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)
        at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:194)
        at com.backend.rest.UserResourceImpl.validateGuest(UserResourceImpl.java:100)
        at com.backend.rest.UserResourceImpl.register(UserResourceImpl.java:77)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
        at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
        at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
        at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
        at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
        at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
        at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.ClassCastException: $Proxy84 cannot be cast to com.backend.rest.validation.validator.NotEmpty
        at com.backend.rest.validation.validator.NotEmptyValidatorImpl.initialize(NotEmptyValidatorImpl.java:18)
        at org.hibernate.validator.internal.engine.ConstraintTree.initializeConstraint(ConstraintTree.java:447)
        ... 49 more

and I know java.lang.ClassCastException: $Proxy84 cannot be cast to Clazz is a clasic spring exception when you don’t use interfaces
but here I do use and NotEmpty si an annotation

Please tell what do I do wrong?

ps. I use this versions of frameworks

   <properties>
    <spring.version>3.1.1.RELEASE</spring.version>
    <hibernate.version>4.1.3.Final</hibernate.version>
    <jersey.version>1.12</jersey.version>
    <validation.api.version>1.0.0.GA</validation.api.version>
    <hibernate.validator.version>4.3.0.Final</hibernate.validator.version>
  • 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-05T13:11:54+00:00Added an answer on June 5, 2026 at 1:11 pm

    I want to thank you each for spending time on this issue.

    The error comes from others implemented annotations that have this constraint validator.
    @Constraint(validatedBy = {INotEmptyValidator.class}).
    This was done for sure by mistake.

    Finally This is the good exemple of doing bean validation specifying constratint validator @Constraint(validatedBy = {INotEmptyValidator.class}) as interface.
    The implementation NotEmptyValidatorImpl is a spring bean.

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

Sidebar

Related Questions

In my web project I have a TestStreamingService.svc file containing a REST service. The
I have created a WCF REST style service in my project. In development I
I have a WCF Rest Service project set up serving JSON datastructures. I have
I have a WCF REST 4.0 project based on the the WCF REST Service
I have a REST service that I would like to require client certificates. The
I have a REST service that gets a GET request, and I want it
I have a REST service consumed by a .Net WCF client. When an error
I have a REST service that returns a collection that contains non- normalized data.
I have a REST service and I want to have a helper class that
So I have wcf rest service which succesfuly runs from a console app, if

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.