javax.validation.ValidationException: Unable to find default provider - java

I am currently working on Spring MVC web app and trying to hook up validation using the #Valid annotation. When I fire up the application I'm getting the following exception:
javax.validation.ValidationException: Unable to find a default provider
I have Hibernate Validator 3.1.0.GA on the classpath as well as javax validation 1.0.0.GA, Hibernate Core 3.3.1.GA and Hibernate Annotations 3.4.0.GA.
Is there an incompatiblity in those versions that I'm not seeing, or can anyone think of any reason why I'm still getting this exception with Hibernate Validator on the class path?
Cheers,
Caps

See this answer : https://stackoverflow.com/a/3989936/325742
To fix, Add this maven dependency Hibernate Validator Annotation Processor.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.1.0.Final</version>
</dependency>
That's the latest stable version of that artifact, as seen from here
Generic way of finding a dependency
Let's say that you got a a NoClassDefFoundError stating that the class org.postgresql.Driver was not found.
Use Jarvana to search for a dependency that can provide org.postgresql.Driver like so : http://www.jarvana.com/jarvana/search?search_type=class&java_class=org.postgresql.Driver which gives
Translate the above dependency into maven dependency format :
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
Confirm that the above is available at Maven Central by searching like this : g:"postgresql" AND a:"postgresql"
(where g stands for GroupID and a stands for artifactID)
Finally, add it to your pom.xml
Finding Dependencies using m2e
If you have an approximate idea of the dependency needed or can figure out the one you need given a list, then m2e's dependency search can be the quickest way of adding a dependency to your pom.xml
Steps :
Click on the Dependencies tab (A) in your pom.xml
Click on Add (B)
Search for the dependency by groupId/artifactId (C)
Double click the required one from the search results to have it added directly to your pom.xml (D)
A-D marked in the following snapshot :
Finding dependencies in IntelliJ Idea
In IntelliJ, looking up a dependency is much easier. All you need to do, is to make sure that the maven central repo has been indexed by IntelliJ like so:
And then, go into the pom, do a dep+Tab (or an Alt+Insert as shown here), and this is what you get:
If you are in a class which has an unresolved import, then the quick fix gives you an option of searching and adding the corresponding maven repo by doing an Alt+Enter on the missing Class/Package:
Awesome I say !

Hibernate Validator 3.1 is not a JSR303 provider. You need to upgrade to Hibernate Validator 4 or later.

This happened to me without Hibernate.
Running great on my PC, it didn't work on my EC2 Linux server.
The reason was an existence of validation-api-1.0.0.GA.jar file under /usr/share/tomcat/lib.
Once validation-api-1.0.0.GA.jar deleted, it worked great.

In my case, I had the same problem, but it was happening because the jar of hibernate-core version 4.1.8.Final downloaded by maven was corrupted. I swithed to version 4.1.6.Final and it started working. I was using STS and spring repositories.
Hope this helps someone.

In same Situation i update my Jar version only for anotations from hibernate-anotation and hibernate-common-annotation to Hibernate4 anotations which are listed below.
For Hibernate 4 you can use this jars-
1-hibernate-commons-annotations-4.0.5.Final
2-hibernate-validator-4.2.0.Final
Hope this will work for you also.

I received the following error:
Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to get available provider resolvers
I discovered that in my WEB-INF/lib directory I had two versions of Validator.class present in both of the following jar files:
org.springframework.context-3.1.1.RELEASE.jar
com.springsource.javax.validation-1.0.0.GA.jar
I removed the com.springsource.javax.validation-1.0.0.GA.jar from the WEB-INF/lib directory because it is older and no longer supported. After doing so, my application worked perfectly. I learned from other posts that my problem had something to do with duplicate versions of the same file on the classpath. I figured out which file was causing the problem after reading Spring 3 Validation

Related

Spring, Maven: Correct the classpath of your application

I am trying to create a maven version of the gradle-based treehouse 'unit-testing-a-spring-application' project used in this course. See course code here.
After not being able to build initially, I ended up adding dependency versions specified in the original gradle build file. Maven will build fine, but running the app gives this:
The following method did not exist:
org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)
Ljava/lang/String;
The method's class, org.springframework.data.repository.config.RepositoryConfigurationSource, is
available from the following locations:
jar:file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-
commons/2.1.6.RELEASE/spring-data-commons-2.1.6.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class
It was loaded from the following location:
file:/C:/Users/home/.m2/repository/org/springframework/data/spring-data-commons/2.1.6.RELEASE/spring-
data-commons-2.1.6.RELEASE.jar
Action
Correct the classpath of your application so that it contains a single, compatible version of
org.springframework.data.repository.config.RepositoryConfigurationSource.
Several similar problems are solved here on S.O. by changing the version of some related dependency. I have tried various versions of the following to no avail (I stick normally with spring-boot-starter-parent v2.1.4 cause it works all the time with my projects):
spring-data-commons
spring-boot-starter-parent
I see the needed class below listed in my project Dependencies directory, but what dependency versions will work in this case? How can I solve this otherwise?
org/springframework/data/repository/config/RepositoryConfigurationSource.class
I looked at your code and found some mistakes. Since your project is a spring-boot one, you mustn't add direct spring dependencies in your pom file. Instead try to use spring-boot based dependencies. For instance, instead of having such this dependency:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.9.2.RELEASE</version>
</dependency>
You must have the following one in your pom file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Error in javax.persistence.PersistenceContext.synchronization()

I am trying to build my Jhipster Spring boot application in maven. However, Maven is not building in the debug mode. Otherwise, it is working fine.
I have added following dependency, didn't help.
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
Description:
An attempt was made to call the method javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType; but it does not exist. Its class, javax.persistence.PersistenceContext, is available from the following locations:
jar:file:/C:/Users/User/Documents/audio-book-admin/lib/javax.persistence.jar!/javax/persistence/PersistenceContext.class
jar:file:/C:/Users/User/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.2.Final/hibernate-jpa-2.1-api-1.0.2.Final.jar!/javax/persistence/PersistenceContext.class
jar:file:/C:/Users/User/.m2/repository/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar!/javax/persistence/PersistenceContext.class
It was loaded from the following location:
file:/C:/Users/User/Documents/audio-book-admin/lib/javax.persistence.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.persistence.PersistenceContext
So, How can I properly correct classpath of my application to reslove the above issues? I am new in Spring boot!
First remove in your repository maven the directory hibernate and then make a
maven clean install to re import correctly your dependencies.
if it still doesn't fix your problem make a maven tree:dependency to detect what dependence is causing issue and exclude it in your pom

Jersey dependency conflict

I'm implementing a dropwizard server app on top of an existing project. building with maven.
I'm currently in jar hell, and it's not fun. I have a pom file that's rather convoluted. I have a big problem with jersey dependencies packaged with hadoop/glassfish/com.sun. com.sun.jersey:jersey-core:jar1.19 is conflicting with org.glassfish.jersey.core:jersey-client:jar:2.22.2. I tried adding some exclusions to make it use the 2.22.x version, but it's still giving me the error seen here. I've been combing through the dependency tree and adding exclusions where I see fit, but can't seem to get it right. Here is my pom file.
Personal experience tells me that you should check ALL your dependencies (especially the ones you developed in-house) if you have the old jersey version as a dependency in there.
That's what solved a similiar problem for me.
If you do :
mvn dependency:list -Dverbose
(grep for filtering results)
it gives u the list of dependencies(transitive ones also).Check the version of sun jersey or glassfish jersey that's being used in your application.
If you do :
mvn dependency:tree -Dverbose -Dincludes=jersey-server
you will see the graph of where any version of jersey-server is coming from a parent.
I had a hadoop-client and an in-house rest-bus-client using a version of sun jersey(1.9.x) which i needed to remove. I tried in maven and it simply worked.
Also, this jersey version unmatch caused the following issue for me in dropwizard.
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;

java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured

Getting java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured, while using gRPC(google pub/sub) to publish/consumes messages from Kafka.
Try adding a runtime dependency on netty-tcnative-boringssl-static. See gRPC's SECURITY.md. Note that the version of netty-tcnative necessary changes over time; you should look at the version of the document for a particular release (e.g., this is for 1.2.0).
Finally, went back to boot class class path approach. Prefixed the jetty-alpn.jar to boot class path and it starts working fine in cloud foundry now.
Adding the ALPN client JAR which matches my JDK version fixed this issue for me. In eclipse, you need to set up the jar as a bootstrap entry for the tomcat server.
You can find more info about it here : https://medium.com/#Parithi/jetty-alpn-npn-has-not-been-properly-configured-solution-418417ee6502
As suggested by google, use jetty container instead of tomcat, this solution works, but in our production, applications deployed on tomcat container, but of course I need it to work on tomcat in production.
On debugging the gRPC code, found that guava version causing the issue, updated the guava version 18.0, (where in some classes missed in previous versions), solved the problem , but failed while deploying in CF
Customized emebed-tomcat-core, and it works fine consistently, but again, team say no to custom tomcat container.
Java –jar apm-asset-xxxx.jar – works fine locally, but need to provide a custom command to CF start, didn’t have luxury to change the CF start process.
Finally, trick, the class loader to use tcnative-boring-ssl, library instead of tomcat-core library at runtime, by providing the following dependency in pom.xml. For the past 3 days, this solution is working CF.
org.springframework.boot
spring-boot-starter-web
org.hibernate
*
org.apache.tomcat.embed
tomcat-embed-core
org.apache.tomcat.embed
tomcat-embed-core
provided
Maven manifest plugin to promote the tc-native library to the top in the classloader.
In POM, try to place the gRPC dependency before the spring boot dependency (the order of dependencies matters). I did that and the issue was solved. For example:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-language</artifactId>
<version>0.13.0-beta</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

spring-webflow jars not available

I have wasted a 4 hours on finding a reason for not adding of webflow jars tp the reference library of my my modular maven project which is generated from appfuse.I want to add a webflow to this project. But when I do the registering as below, I get an error (I have still not run the project).
error is
Multiple annotations found at this line:
- Class 'org.springframework.webflow.mvc.servlet.FlowHandlerAdapter'
not found
But I have included the webflow dependencies in my pom in my web module project. But when I go the the reference library I can not find the webflow jars as well. I think this is the reason for this, But I can not wind a way to get the jars in to the reference library.
The generated pom is very lengthy. I will add it if it is needed.
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.2.RELEASE</version>
</dependency>
Is there a compatibility issue with the spring versions. I am currently using 4.0.0.RELEASE I have changed it to 4.0.2.RELEASE as well. But no luck. I can not find a meaningful solution for this. I really appreciate some help on this.
Thanks
In Eclipse, right click the project and go to build path -> configure build path
From here, go to libraries and check that the Maven dependencies library is in there.
If its not click add library click maven managed dependencies, next, finish
Should add the libraries to the eclipse project

Categories