What is the right place for javax.validation - java

I am working on a simple project as a point of reference for new projects or to try new technologies. The project has Hibernate & Spring capabilities.
I tried to add some anotations for validate fields. Those are the validation which I am using
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
The problem is that I need javax.validation dependecy and There are a lot of jars which includes those clases but none of Spring or Hibernate.
Which one is the standard?
Note: I check the dependency in the big project and I am using the validation-api

Try the library "Apache Geronimo JSR-303 Bean Validation Spec API", the jar is "geronimo-validation_1.0_spec-1.0-CR5.jar".
Look at this link :
http://www.findjar.com/jar/org/apache/geronimo/specs/geronimo-validation_1.0_spec/1.0-CR5/geronimo-validation_1.0_spec-1.0-CR5.jar.html
Here is maven part to add it :
http://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-validation_1.0_spec/1.0-CR5

Use
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>
or
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.0.0.GA</version>
</dependency>
depending on which version of the API you want to use. Note that the API is not enough, of course you also need an implementation (if you don't deploy your application in an Java EE application server). The implementation usually has a transitive dependency on the correct API jar.

Related

java.lang.IncompatibleClassChangeError: class org.springframework.session.hazelcast.PrincipalNameExtractor

I am trying to configure spring session backed by hazelcast for spring security oauth2 client application.
I followed below link to configure hazelcast.
https://docs.spring.io/spring-session/docs/current/reference/html5/guides/java-hazelcast.html
However, classes annotated with #SpringBootTest started failing due to below error:
java.lang.IncompatibleClassChangeError: class org.springframework.session.hazelcast.PrincipalNameExtractor has interface com.hazelcast.query.extractor.ValueExtractor as super class
My pom.xml of spring boot 2.5 application contain below two new dependencies for hazelcast configuration
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-hazelcast</artifactId>
</dependency>
As per below stackoverflow post , issue seems to be that ValueExtractor is available for two different versions in maven dependencies
IncompatibleClassChangeError: class ClassMetadataReadingVisitor has interface ClassVisitor as super class
Hence, I checked maven dependencies and can see that PrincipalNameExtractor is available from 2.5 version of spring-session-hazelcast while ValueExtractor is available from 4.2 version on com.hazelcast. However,
spring-session-hazelcast is using 3.12.12 version of com.hazelcast for compilation.
So should I use 3.12.12 version of com.hazelcast to resolve this issue or am in misinterpreting the issue? I prefer to use latest version.
Starting from spring-sessions v2.4.0, you can use Hazelcast v4.x with configuring Hazelcast4PrincipalNameExtractor and Hazelcast4IndexedSessionRepository for the session repository. The only difference is the class names with 4 indicator. That is, HazelcastIndexedSessionRepository becomes 4.x compatible with Hazelcast4IndexedSessionRepository.
Here is a guide covering both versions: https://guides.hazelcast.org/spring-session-hazelcast/

opendj-core 6.5.0 maven dependency

On OpenDJ 2.6.4, i’m using the dependency “opendj-ldap-sdk” in order to use the
following classes:
org.forgerock.opendj.asn1.ASN1;
org.forgerock.opendj.asn1.ASN1Writer;
org.forgerock.opendj.ldap.ByteStringBuilder;
I checked that the same classes exist on Directory Services 6.5 on lib\opendj-core.jar but i cannot find the maven dependency to use it (in a context of migration from OpenDJ 2.6.4 to Directory Services 6.5).
I’ve found this dependency:
<dependency>
<groupId>org.codice.org.forgerock.opendj</groupId>
<artifactId>opendj-core</artifactId>
<version>3.0.0.ALPHA1</version>
</dependency>
but the version doesn’t match..
Where can I find the dependency?
You can unzip DS-6.5.0.zip and then add the <systemPath> element to your maven dependency. See https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies .
For a more robust mechanism, if you intend to use Directory Services 6.5 in production, then I would recommend that you contact your ForgeRock support. They will explain to you how to compile your plugin(s) against this version.

maven dependency for play.filters.cors.CORSFilter

I am trying to add a CORS Filter to my Lagom Framework REST API. I added a Filters class, as per the documentation, however it cannot to find the package for CROSSFilter. Need MAVEN dependency flay framework CrossFilter
You need filters helper package
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>filters-helpers_2.11</artifactId>
<version>2.5.13</version>
</dependency>
Different versions:
https://mvnrepository.com/artifact/com.typesafe.play/filters-helpers_2.11
https://mvnrepository.com/artifact/com.typesafe.play/filters-helpers_2.10
API Docs:
https://www.javadoc.io/doc/com.typesafe.play/filters-helpers_2.11/2.5.13

Cannot resolve Neo4j annotations in Eclipse

I'm trying to import various Neo4j annotations in Eclipse with Maven
I have
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
But I get:
The import org.springframework.data.neo4j.annotation.Fetch cannot be resolved
when I try to import #Fetch, #RelatedTo and #GraphId. Curiously eclipse shows that the annotations #Query, and #QueryResult are present on org.springframework.data.neo4j.annotation, but only those two and none of the other annotations. All the documentation I can find says the annotations should be there, but it just looks are if they're not.
I downloaded the spring-data-neo4j.jar, extracted it, and it appears the annotations are not there. I changed to the 3.4.1 release and everything's ok.
Update.
This problem was actually because the quick start example for using neo4j on the Spring website is actually using annotations that are no longer supported by Neo4j 4 whilst showing the dependency to use as Neo4j 4.
Neo4J 4 doesn't use these annotations anymore.

How make a Maven package using JPA, but independent of service provider; and later how to plug in my service provider by user of this package?

I'm not sure if it's even possible...
I have some design patterns, which I want in my special Maven package (#1) - all these patterns use javax.persistence. I don't want this package to depend on Hibernate or any other implementation of JPA. Just let it depend on JPA API, as it is defined by JCP.
My second Maven package (#2) is to use this first one, and to specify which JPA implementation to use (f.e. Hibernate).
Now, how do I define my pom.xml for both of these packages (let JPA implementer for #2 package be Hibernate)?
JPA defines a package javax.persistence, it contains Annotations, Interfaces and so on. This package is completely Provider independent. It should contains every thing you need to implement provider independent services basd on JPA.
The only thing you need is to put an dependency to an javax.persistence containing maven artifact in your Maven module #1.
There are several maven artifacts containing this javax.persistence package. For example:
<dependency>
<!-- JPA 1.0 -->
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<!-- JPA 2.0 -->
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
In you Maven Module #2 you need to put an dependency to Module #1 and an dependency to the JPA provider (for example Hibernate) you like to use.
(If the provider you use, use an other dependency to the javax.persistence package, then you need to exclude one of them.)
Assuming that you don't want Hibernate to be in the compilation path (to prevent developers from using vendor specific extensions), but you still want to have it packaged in the final artifact, you should use the <scope>runtime</scope> when defining your JPA implementation.

Categories

Resources