Domanda

I'm running an application in Tomcat using Weld (org.jboss.weld.servlet:weld-servlet:2.0.2.Final with maven) to produces ValidatorFactory and Validator components like this:

@Produces 
@Default 
@javax.enterprise.context.ApplicationScoped
public ValidatorFactory getInstance() {
    return Validation.byDefaultProvider().configure().buildValidatorFactory();
}

And

@Produces @javax.enterprise.context.ApplicationScoped
public Validator getInstanceValidator() {
    return factory.getValidator();
}

When I inject Validator and calls method Validator.forExecutables(), I'm getting this exception:

org.jboss.weld.proxies.Validator$1284425531$Proxy$_$$_WeldClientProxy 
cannot be cast to javax.validation.executable

But if I inject ValidatorFactory and calls ValidatorFactory.getValidator().forExecutables(), all works fine.

There are wrong in my code? Or there are another procedure to avoid this error?

EDIT

Analyzing Hibernate validator source code, I see that ValidatorImpl implements both Validator and ExecutableValidator interface. When weld creates the proxy, it implements only methods found in Validator interface, and not ExecutableValidator methods.

There are way to resolve this?

È stato utile?

Soluzione

Which version of Hibernate Validator is this?

Actually Hibernate Validator's CDI ValidatorBean returns ExecutableValidator as type as well, so the proxy should be created for this. I vaguely remember that we had issues with that in a Beta release, so it might be you're still using that one.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top