Hello I am trying to write an example using Hibernate Validation in Karaf but I am having trouble with some dependency errors.
What I did so far is download a fresh version of Karaf (version 4.1.4). Start this and enter the command “feature:install hibernate-validator”. My understanding of Karaf is that this should download hibernate validator and all its dependencies. When I do “bundle:list” I can see the bundles installed by the feature and they are all marked as active.
Next I deploy my application, which at the moment consists of one class with the following code;
class HibernateValidationProviderResolver implements ValidationProviderResolver {
@Override
public List getValidationProviders() {
List providers = new ArrayList(1);
providers.add(new HibernateValidator());
return providers;
}
}
public class App {
public App(){
System.out.println("(Ex HV App) Start.");
ValidatorFactory factory = Validation.byDefaultProvider().providerResolver(
new HibernateValidationProviderResolver()).configure().buildValidatorFactory();
Validator validator = factory.getValidator();
System.out.println("(Ex HV App) Ready.");
}
}
(note, I use blueprint to create an instance of the class)
At the moment in the META-INF of my project I put DynamicImport-Package: * rather than list all packages under Import-Packages as I want to make sure my issue is not related to my bundle missing a dependency.
DynamicImport-Package: *
I next proceed to install my example bundle “bundle:install –s mvn:example/app/0.1.0”
However when I do so I get the following error:
Caused by: java.lang.ClassNotFoundException:
com.sun.el.ExpressionFactoryImpl not found by org.hibernate.validator [70]
My understanding is that Hibernate Validator is starting but then fails because it cannot find the Expression Language dependency. That said, if I do bundle:list I can see that the feature:install done previously has install the expression language bundle as I can see the following;
66 │Active│80│ 2.2.4 │ Expression Language API 2.2
69 │Active│80│ 2.2.4 │ Expression Language 2.2 Implementation
Can someone help me understand what I am doing wrong?
From what I have seen in the Karaf repository, they are still using HIbernate Validator 5.4. We fixed an issue regarding javax.el and OSGi during the 6.0.x lifecycle which looks a lot like your issue. You could work around the issue by using the externalClassLoader() trick and push your application class loader but I would advise you to upgrade: HV 6 is faster and should fix your issue.
It’s compatible with HV 5.4 so you shouldn’t have any compatibility issue if it’s an existing application.
Answering to myself, looks like we have some issue installing our feature on a vanilla Karaf. So maybe you’ll be lucky (we are in our integration tests, don’t know why) but when I tried upgrading Karaf to 6.0.8.Final, I got the following error:
Hello again, I am not sure if this is an issue with hibernate validator but thought best to report this here. So as explained using the bundles in the linked feature file does work.
However if the bundle “mvn:javax.el/javax.el-api/3.0.0” is already installed then the following error comes out:
Caused by: javax.validation.ValidationException: HV000183:
Unable to initialize 'javax.el.ExpressionFactory'.
Check that you have the EL dependencies on the classpath,
or use ParameterMessageInterpolator instead
If bundle “mvn:javax.el/javax.el-api/3.0.0” is installed after the hibernate validator bundles then everything still works. However this means that for example the hibernate validator feature would always needs to be installed before the open jpa feature because this latter contains the bundle “mvn:javax.el/javax.el-api/3.0.0”
For me it is not a problem to change the order of how features/bundles are installed. However would like to know what causes this issue.
We also use Pax Exam. You should be able to make it work if you follow what we did.
BTW, I see you mention the annotation processor in your dependency for the 2nd time, it’s not something you need at runtime. The annotation processor is used to check that the annotations you used make sense at compile time. You should only enable it when you build your project.