java.lang.NoSuchMethodError: org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerIfNotAlreadyRegistered - spring

I am using CRUDRepository to perform crud operations using JPA , but I am getting this error:
java.lang.NoSuchMethodError:
org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.registerIfNotAlreadyRegistered
Please help.

It comes from this commit:
https://github.com/spring-projects/spring-data-commons/commit/6677612f8eac7a7ab67206a5709b6e94cc51028b
So you'll need at least spring-data-commons 1.10.0.RELEASE:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.10.0.RELEASE</version>
</dependency>
But: if this is happening is probably because you've a conflict between versions, so it's better if you find out why you are loading an older spring-data-commons

I was able to solve this error , earlier i was using spring-data-jpa.1.7.2.RELEASE.jar , now i switched on to spring-data-jpa.1.6.0.RELEASE.jar and it solved the problem
thanks for help.

Often this happens when you have 2 dependencies in your maven pom.xml file with the same "groupId" but different versions.
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-commons-core -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.1.RELEASE</version>
</dependency>
Common "groupId"'s should have the same version number.

Related

java.lang.ClassNotFoundException: io.netty.handler.logging.ByteBufFormat

I'm on integrating a third-party library into our application. For that I have added all the dependencies, however facing below error stack on application run.
Error stack-trace:
`
Caused by: java.lang.ClassNotFoundException: io.netty.handler.logging.ByteBufFormat
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 31 common frames omitted
`
Maven dependencies:
`
<dependency>
<groupId>com.affinda.api</groupId>
<artifactId>affinda-api-client</artifactId>
<version>0.4.2</version>
</dependency>
<dependency>
<groupId>com.microsoft.rest</groupId>
<artifactId>client-runtime</artifactId>
<version>1.7.14</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-runtime</artifactId>
<version>1.7.14</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-client-authentication</artifactId>
<version>1.7.14</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.84.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
<version>4.1.84.Final</version>
</dependency>
`
I did check that ByteBufFormat is in netty-handler library from the docs and did check the dependency tree but haven't got any clue.
It might be too late, however I had the same problem.
The cause is that another dependency is overriding the netty version in your final pom. In my case it was spring boot dependencies (2.2.0-RELEASE) which was overriding netty to version 4.1.42Final instead of needed 4.1.86Final.
If you want to check who is responsible, you can run maven with goal help:effective-pom and search for the effective netty version management owner.
In order to solve the issue you can just specify the netty version among maven properties:
<properties>
.
.
<netty.version>4.1.86.Final</netty.version>
</properties>
In this way you will put back the expected netty version and everything will work like a charm.
Be careful to check that the other library is still working as well.

Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

I am currently playing with some proof-of-concept work in Spring Boot and GCP data storage.
My pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-data-datastore</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
Issue: Spring Boot fails to start
When I attempt to launch the application, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:251)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:264)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
What I tried
I tried adding the Actuator dependency.
But that did not do the trick.
I cannot figure out what dependency I am missing. I see the class definition here in 5.3.0-M2 documentation, but I'm not sure what dependency it exists in.
I also tried adding following metrics dependencies:
spring-cloud-gcp-starter-metrics
spring-metrics
spring-cloud-stream-metrics
I searched in findjar.com with no luck.
I wouldn't mind disabling it as well if that is possible.
Update:
I added:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.1</version>
</dependency>
Which gives me a new error:
An attempt was made to call a method that does not exist. The attempt
was made from the following location:
org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
The following method did not exist:
'void org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'
The method's class,
org.springframework.context.ConfigurableApplicationContext, is
available from the following locations:
...
Action:
Correct the classpath of your application so that it contains a
single, compatible version of
org.springframework.context.ConfigurableApplicationContext
I was able to solve this by downgrading Spring Boot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
Guess it's just not compatible with 2.4.0 yet.
Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.
I don't have the spring-cloud dependency, but when upgrading to Spring Boot 2.4 from 2.3 I got the same error.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/core/metrics/ApplicationStartup
Per conversation in this thread (https://github.com/spring-projects/spring-boot/issues/24880) I upgraded to Spring Framework 5.3.3 and it fixed the problem.
I had the same issue caused by an old version of spring-context JAR file loaded instead of the appropriate version.
Ensure that there were no reminiscence of old libraries in your classpath.
I had a similar issue, and it was resolved by adding the following maven dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.3.8</version>
</dependency>
I was having the same issue but with:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.9.RELEASE</version>
<scope>test</scope>
</dependency>
And the error disappeared after I upgraded to:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.3</version>
<scope>test</scope>
</dependency>
May this help, upgrade spring-cloud to the latest version.
This works for me when I faced your first error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
See the twitter thread here, thanks to Stéphane and Arnaud for the help.
I had the same problem, but that was caused by spring-security-ldap that i also import in version 5.4.x
Upgrade spring-security-ldap to version 5.5.0 solved the problem for me.
I had this issue when adding a Spring Boot test to a library for the first time. In my case, the library did not have a Spring Boot application.
This did the trick:
#SpringBootApplication
public class TestApplication {
public static void main(final String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Using only spring-boot-starter-test as a Spring dependency.
Check if another dependency doesn't have dependency to spring-core with older version
May this will help someone, who is facing this error.
=> Error should look like this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:229)
at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:112)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:67)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:91)
Solution to the Problem:-
Go to Project folder\ Right click\ Maven\ Update maven project.
Check your Spring version (pom.xml-> view the properties).
Change the Spring version to an older/new version..Otherwise use this
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring.version>5.2.0.RELEASE</spring.version> <!--add this version-->
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework</groupId> <!-- sql dependency for jdbc-->
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
After adding above things, Save it(Please wait for the code to build..).
Run your Program
All The Best Guys, Let's Move Togther
I had the same Spring Boot ClassNotFoundException ApplicationStartup issue, the solution was for me to ensure that the spring boot version in my gradle plugin is the same than the dependencies in my build.gradle.kts like:
plugins {
id("org.springframework.boot") version "2.5.3"
...
}
dependencies {
implementation("org.springframework.boot:spring-boot:2.5.3")
...
}

JSF correct use of jsf-api dependency

Ok, I am a little confused on the differences between jsf-api implementations.
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
I am not sure what the differences are between these two. I thought they do the same thing and allow the javax.faces imports but now I have confused myself. Can anyone please explain these two differences? Thanks :)
There was somes changes with the groupId of the Maven JSF-API dependency since the first version. For JSF 2.2 (current version as I'm writing this), you should use the following recommended dependency, if you are running in a container supporting JSF:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
If your container does not support JSF (like Tomcat), use the following dependency if you want to use Mojarra (the default JSF implementation):
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.8</version>
</dependency>
Other recommmendation and information are available on the official page of JSF.

Spring Data JPA Error for 1.7.0.M1 query lookup strategy Exception

I was trying to Integrate Spring Data JPA with custom queries added in my repository.The following error made me crazy
"You have defined query method in the repository
but you don't have no query lookupstrategy defined.
The infrastructure apparently does not support query methods!"
Can Anyone tell me how to solve this?
Upgrade the spring-data-commons dependency to 1.9.0.RELEASE.
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>1.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
It was solved when downgraded to 1.6.2.RELEASE
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<!-- <version>1.7.0.M1</version> -->
<version>1.6.2.RELEASE</version>
</dependency>

multiple SLF4J bindings Error with activemq-all-5.6.0.jar

When I upgrade to activemq-all-5.6.0
I get this error during server startup
SLF4J: Class path contains multiple SLF4J bindings
I don't have this issue when using activemq-all-5.5.1
On checking I do find that there StaticLoggerBinder.class in both activemq-all-5.6.0.jar and slf4j-log4j12-1.5.10.jar which is causing the issue
Please do help in debugging this issue
My pom.xml is as follows
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.10</version>
<scope>runtime</scope>
</dependency>
The active mq dependency is like this
Old Version 5.5.1 (This works)
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.5.1</version>
</dependency>
New Version 5.6.0 (This gives the error)
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.6.0</version>
</dependency>
Thanks in advance.
The ActiveMQ guys use the Maven Shade Plugin to create the activemq-all "ueber" jar. Somewhere between version 5.5.1 and 5.6.0 they added the org.slf4j:slf4j-log4j12 dependency - hence your problem.
Unfortunately because they used the shade plugin you can not use exclusions in your activemq-all dependency definition in your POM.
Instead you will need to completely replace the activemq-all dependency with all the required individual dependencies (except of course the org.sl4j-log4j12 one).
The following page details all the required dependencies:
http://activemq.apache.org/initial-configuration.html#InitialConfiguration-RequiredJARs
Alternatively the following is the list of all dependencies (required and optional) included in the activemq-all jar (taken from the configuration of the shade plugin in the activemq-all pom):
org.apache.activemq:activemq-camel
org.apache.activemq:activemq-core
org.apache.activemq:activemq-console
org.apache.activemq:activemq-jaas
org.apache.activemq:activemq-optional
org.apache.activemq:kahadb
org.apache.geronimo.specs:geronimo-jms_1.1_spec
org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec
org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec
org.apache.geronimo.specs:geronimo-annotation_1.0_spec
org.slf4j:slf4j-api
org.slf4j:slf4j-log4j12
log4j:log4j
Hope that helps.
I had the same problem while using Spring. What helped me was replacing the dependency of activemq-all with:
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.14.3</version>
</dependency>
Hope this will help anyone...

Resources