How to add properly Data REST dependency in Spring Boot Maven project? - java

I try to add Spring Data REST dependency using this dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
After adding this dependency I catch an exception - java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;
And the Action suggestion: Correct the classpath of your application so that it contains a single, compatible version of org.springframework.plugin.core.PluginRegistry
I tried to add this dependency to fix the problem:
<dependency>
<groupId>org.springframework.plugin</groupId>
<artifactId>spring-plugin-core</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
But it didn't help me.
How could I fix this problem?
I use Spring Boot version - 2.2.7.RELEASE, Maven version - 3.3.9

Related

SpringBoot 2.6.1 incompatibility with Querydsl Mongodb?

I'm upgrading a Java 11 (SpringBoot 2.4.1) application to Java 17 and Spring 2.6.1.
While using SpringBoot 2.4.1, I had these dependencies:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
...
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-mongodb</artifactId>
<version>${querydsl.version}</version>
</dependency>
${querydsl.version} is managed by SpringBoot dependency management.
But when upgrading to SpringBoot 2.6.1 I'm facing this incompatibility:
spring-boot-starter-data-mongodb brings mongodb-driver-core/4.4.0
querydsl-mongodb brings mongo-java-driver/3.12.8
And I get this error:
The called method's class, com.mongodb.connection.ClusterSettings, is available from the following locations:
jar:file:/C:/Users/SXBN9329/.m2/repository/org/mongodb/mongodb-driver-core/4.4.0/mongodb-driver-core-4.4.0.jar!/com/mongodb/connection/ClusterSettings.class
jar:file:/C:/Users/SXBN9329/.m2/repository/org/mongodb/mongo-java-driver/3.12.8/mongo-java-driver-3.12.8.jar!/com/mongodb/connection/ClusterSettings.class
Action:
Correct the classpath of your application so that it contains compatible versions of the classes com.mongodb.connection.DefaultClusterFactory and com.mongodb.connection.ClusterSettings
Has somebody any idea to solve that?
I've found the reason: another module had a dependency to spring-data-mongodb. So I had both spring-data-mongodb and spring-boot-starter-data-mongodb.
It appears that this doesn't work well with QueryDSL ^^
I've replaced spring-data-mongodb by spring-boot-starter-data-mongodb in the other module, and it's working now.

Resolving version conflict due to external transitive dependency

I am getting below error -
servlet [jersey] in context with path [/GeneralService] threw exception
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri
I am getting this error after adding a new external dependency which has below dependencies in it's pom.xml file-
jersey-client - 2.25.1 which in turn depends on -
javax.ws.rs-api - 2.0.1
when I exclude javax.ws.rs-api - 2.0.1 from the dependency heirarchy, I don't get the above mentioned error but then this external dependency code doesn't work as it depending on this artifact.
My main application has below jersey related dependencies in the pom.xml
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.18</version>
<exclusions>...</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.18</version>
</dependency>
So my main application depends on the jersey version 1.18 and external dependency depends on jersey version 2.0.1.
I am unable to figure out a way to resolve this so that it runs smoothly. Any help is appreciated!
You need to use a consistent version of jersey, preferably 2.x. So update all your dependencies to 2.x and then figure out step by step which changes you need to make in your own code to make that work.
There is no sensible way to use different versions of the same artifact simultaneously.
The jersey version 1.18 use java.ws.rs version 1.1.1 as compile dependency. See:
https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle/1.18
Since you're talking about using jersey 2.25.1, I suggest to upgrade your pom to glassfish jersey 2.25:
https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-client/2.25.1
like this:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.25.1</version>
</dependency>
Then the dependency to java.ws.rs will be 2.0.1.
As for jersey-spring artifact, it don't depends on java.ws.rs

Integrate Apache Mahout with ElasticSearch in Spring Boot

I have a Spring Boot application integrated with ElasticSearch.
When i am trying to add Apache Mahout as a maven dependency, the application is no longer running with this error:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/util/Accountable
If i remove the mahout dependency the application is running.
pom.xml:
<dependencies>
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
The dependency is resolved by maven, the project compiles with no error but when i start it, the server stops.
Any idea?
Thank you
In order to use the latest versions of Elasticsearc v6.x and Spring-boot, you have to focus on the matrix versions. because while I was trying to integrate Elasticsearch v6.2.2 as dependencies into my spring-boot v1.5.X I faced several errors. thus spring-boot v2.x is the compatible one with ES v6.x
so the following link will help you to know the matrix between versions for your project :
https://www.elastic.co/support/matrix#matrix_compatibility
after doing that , use the last version of apache mahout .

java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.jaxrs.provider.ProviderFactory

I upgraded my application's spring version from 3.2.10 to 4.3.16, and also my http-client to 4.3.3 from 4.2.1. While running my application, I am getting error page.
Can you try including the following dependency in your pom?
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle-jaxrs</artifactId>
<version>2.6.0</version>
</dependency>

Spring MVC 4.2.2 and Hibernate 5.0.2 giving error

Below are the dependency version details on the pom.xml
<!-- spring -->
<org.springframework-version>4.2.2.RELEASE</org.springframework-version>
<org.springframework.data-version>1.11.0.RELEASE</org.springframework.data-version>
<!-- hibernate -->
<org.hibernate.hibernate-core>5.0.2.Final</org.hibernate.hibernate-core>
<org.hibernate.hibernate-annotations>3.5.6-Final</org.hibernate.hibernate-annotations>
<org.hibernate.hibernate-commons-annotations>3.2.0.Final</org.hibernate.hibernate-commons-annotations>
<org.hibernate.hibernate-validator>5.2.2.Final</org.hibernate.hibernate-validator>
I'd picked the Hibernate version details from the "spring-orm" pom and found the Hibernate 5.0.2 is compatible with Spring 4.2.2
With the same dependencies in-case of Spring core and Hibernate it's working fine and giving desired result.
But with Spring MVC and Hibernate integration, it's giving below error
Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError:
org.hibernate.cfg.annotations.reflection.JPAMetadataProvider.(Lorg/hibernate/boot/spi/MetadataBuildingOptions;)V
If any further information is needed, please put in the comment section. I will provide the entire configuration details.
Thanks in Advance. :-)
On removing the below dependencies from pom.xml has resolved the issue.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.2.0.Final</version>
</dependency>
Because of this dependencies, there was conflict on the Resolved dependencies.(Refer the pic attached on the question).
hibernate-annotations is not required, It was dependent on older version of hibernate-core and hibernate-commons-annotations
hibernate-commons-annotations (version 5.0.2) is present in hibernate-core as a dependent jar. So it's not required to mention older version in pom.xml

Categories