You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Castor <yg...@gmail.com> on 2017/06/28 14:26:18 UTC
JSR-303 Hibernate Validator with Karaf
Hello, i'm trying to use Bean Validations with Karaf, but i'm having no
success.
First of all, i installed the hibernate-bean-validation feature and added
javax.validation and org.hibernate.validator to my Manifest, with no
success, so i found some references:
http://jungsbluth.de/magnus/blog/2009/07/18/having-fun-with-jsr-303-beans-validation-and-osgi-spring-dm/
http://karaf.922171.n3.nabble.com/Bean-Validation-td4044140.html
And
https://github.com/hibernate/hibernate-validator/blob/master/osgi/integrationtest/src/test/java/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java
Seems to me that i have to wrap the hibernate validator on my own, so a
created the following factory:
public class KarafValidationProviderResolver implements
ValidationProviderResolver {
public final static ValidatorFactory getInstance() {
return Validation.byProvider(HibernateValidator.class)
.providerResolver(new
KarafValidationProviderResolver()).configure().buildValidatorFactory();
}
@Override
public List<ValidationProvider<?>> getValidationProviders() {
return Collections.<ValidationProvider<?>> singletonList(new
HibernateValidator());
}
}
And in my applicationContext i created:
<bean id="validatorFactory"
class="br.com.pcsist.winthor.core.servico.KarafValidationProviderResolver"
factory-method="getInstance" />
The bean seems to be created ok, but when i autowire the validator and run
validator.validate(object); I have the following exception:
java.lang.IllegalArgumentException: No target Validator set
at
org.springframework.util.Assert.notNull(Assert.java:115)[109:org.apache.servicemix.bundles.spring-core:4.2.9.RELEASE_1]
at
org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:252)[107:org.apache.servicemix.bundles.spring-context:4.2.9.RELEASE_1]
I'm not sure how to solve that.
--
View this message in context: http://karaf.922171.n3.nabble.com/JSR-303-Hibernate-Validator-with-Karaf-tp4050878.html
Sent from the Karaf - User mailing list archive at Nabble.com.