Spring Data Dependencies Error - java

I have the folowing Error: "java: name clash:save in JpaRepository and save in CrudRepository have the same erasure, yet neither overrides the other."
I am using Intellij IDEA with dependencies:
Hibernate 5.2.9-5.2.9
Spring Data JPA-1.3.3
Spring-4.3.8.RELEASE
I am using:
#Repository
public interface PropietarioRepository extends JpaRepository<E, K>{}
as Data Access Layer.

4.3.8-release is the latest stable version of Spring. 1.3.3 is a release from 2013, 4 years ago. Its pom indicates that it relies on spring 3.1.4.RELEASE.
Use a recent version of spring-data-jpa, that is compatible with Spring 4.3.8.
The latest stable version, compatible with spring 4.3.8, is 1.11.3: http://docs.spring.io/spring-data/jpa/docs/1.11.3.RELEASE/reference/html/#dependencies.spring-framework

Related

Replace ConditionalOnEnabledEndpoint for Spring Boot 2.6.4

I want to migrate old Spring project which is using this dependency:
org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint
This Class requires import of:
'org.springframework.boot:spring-boot-actuator-autoconfigure:2.0.2.RELEASE'
I tried to use the latest version:
'org.springframework.boot:spring-boot-actuator-autoconfigure:2.6.4' but ConditionalOnEnabledEndpoint is not available. Do you know which class should be used?
It doesn't exist anymore (see https://docs.spring.io/spring-boot/docs/2.6.4/api/). In version 2.2.0 it was deprecated in favour of #ConditionalOnAvailableEndpoint (see https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/api/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.html).

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/

import com.mongodb.client.MongoClient; is not present error seen in java spring boot project

I am using spring parent version 2.4.5 and spring mongodb data module 3.1.8 version and this module internally uses 'mongodb-driver-core version 4.1.2' which seems to be the java mongo driver version being used by the dependency. My problem is I am trying to connect to mongo db cluster on my local using the latest spring boot version and my project uses maven but my intelliJ and eclipse(tried in both) shows import com.mongodb.client.MongoClient; as red meaning both the IDEs are not able to detect this class and find it.
Sharing Code snippet (for giving an idea where the error is) that I am using to create the mongotemplate bean
#Bean public MongoClientFactoryBean getMongoFactoryBean(){ return new MongoClientFactoryBean();}
#Bean public MongoTemplate getTemplate(MongoClientFactoryBean factory){ return new MongoTemplate(factory.getObject(), "some database name")}
I get an error in above method while doing a build java cannot access com.mongodb.client.MongoClient class file for com.mongodb.client.MongoClient not found
Any Idea what is going wrong here and any suggestions to solve this issue?

Using Spring Boot, QueryDSL, and Springfox Swagger together - Guava version mismatch

I'm trying to use QueryDSL for Spring Data predicate resolution as well as Swagger API documentation for my Spring Boot service. However I've run into a problem. When my application starts, I get this error message:
java.lang.NoSuchMethodError: 'com.google.common.collect.FluentIterable com.google.common.collect.FluentIterable.concat(java.lang.Iterable, java.lang.Iterable)
An attempt was made to call a method that does not exist. The attempt was made from the following location:
springfox.documentation.schema.DefaultModelDependencyProvider.dependentModels(DefaultModelDependencyProvider.java:79)
The following method did not exist:
'com.google.common.collect.FluentIterable com.google.common.collect.FluentIterable.concat(java.lang.Iterable, java.lang.Iterable)'
The method's class, com.google.common.collect.FluentIterable, is available from the following locations:
jar:file:/my_m2/com/google/guava/guava/18.0/guava-18.0.jar!/com/google/common/collect/FluentIterable.class
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.google.common.collect.FluentIterable
I've discovered that this is happening because QueryDSL is dependent on Guava 18.0 library, but Springfox / Swagger is dependent on Guava 20.0 library, so I end up with both versions of the library on my classpath and maven seems to prioritize the 18.0 one. How can I fix this dependency mismatch? Is there any way to force QueryDSL to try to use Guava 20.0 (in the hopes that it will still function)? Or could there possibly be any other way around this?
Versions:
Spring Boot version: 2.1.9.RELEASE
This version of Spring Boot uses QueryDSL version: 4.2.1
Springfox Swagger version: 2.9.2
If using Gradle, you can force the use of a specific library version. In this case, you may use the following syntax -
configurations.all {
resolutionStrategy.force "com.google.guava:guava:$guavaVersion"
}
I'm sure there's a similar solution if you use a different build tool.

Multiple annotations found at this line: Factory bean not Found

I am building a Spring project in Spring Tool Suite(3.6.4.RELEASE).
I am trying to upgrade spring framework version from 4.0.3.RELEASE to 4.2.7.RELEASE using maven.
Before upgradation there was no error and everything running smoothly. Now project is compiling and running without error but login page is not showing and also I am getting error in my spring security configuration xml.
Error in spring-security.xml:
Showing following error on STS hovering:
Multiple annotations found at this line:
- Factory bean 'org.springframework.security.config.http.FilterInvocationSecurityMetadataSourceParser
$DefaultWebSecurityExpressionHandlerBeanFactory' not found [config set: mcare-dashboard-web/web-context]
- Factory bean 'org.springframework.security.config.http.HttpConfigurationBuilder
$SecurityContextHolderAwareRequestFilterBeanFactory' not found [config set: mcare-dashboard-web/web-context]
Project Hierarchy:
My pom.xml was like following:
Then I just changed the version number like this:
After that spring-security.xml was showing the error.
Can anybody explain why is this happening?
You state that you are upgrading Spring from version 4.0.3.RELEASE to 4.2.7.RELEASE. However effectively you are upgrading both Spring and Spring Security. This due to having a single version property, named org.springframework-version, to manage both the version of the Spring and Spring Security dependencies.
So changing org.springframework-version to 4.2.7.RELEASE effectively upgrades Spring Security as well.
To fix this you want to have two distinct version properties one for Spring and another for Spring Security. You can than upgrade only Spring or Spring Security.

Categories

Resources