Spring Boot Devtools issue on SpringBoot 2.0.0.M4 - spring-boot

I'm trying to run a Spring boot app using below versions:
<version>2.0.0.M4</version>
<java.version>1.9</java.version>
<spring.version>5.0.0.RELEASE</spring.version>
My application works as expected but when I add the below dependency (spring-boot-devtools), I'm getting an error when I try to run:
mvn spring-boot:run
Dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Exception:
Exception in thread "main" java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader
I have tried to run with old version as below and it works fine.
<version>2.0.0.BUILD-SNAPSHOT</version>
<java.version>1.9</java.version>
<spring.version>5.0.0.BUILD-SNAPSHOT</spring.version>
I was wondering if someone can point us if I'm doing something wrong here, or do we have an issue with 2.0.0.M4?
Thanks
Singh

I encountered the same problem when I was using jdk 11 with my spring boot app. You have to use an older version of the jdk like version 8 and if that does not work then you upgrade your spring boot version. The former worked for me.

I think it is a spring boot dev-tool incompatibility with java version 9.
I met this problem using stable version of spring boot.

This is working in Spring Boot <version>2.0.0.M7</version>
with java 9

I faced the same problem. I had resolved it by reducing the version of JDK to 1.8. however, I am using a lower version of springboot but you can upgrade your JDK version in your case.

The error suggests there is an incompatible JDK, this could be due to multiple JDK on your classpath, and when dev-tool is trying to run the application, it ends up picking the wrong JDK.

Related

Spring Kafka error after upgrading spring boot to 2.6.6

I am facing runtime error after I have upgraded spring boot version from 2.4.0 to 2.6.6 (and spring cloud version 2021.0.2). My application consumes messages from a kafka topic and produces it to another kafka topic after some transformation. I am getting below error as soon as the message is consumed.
ERROR ERROR - - - - applog.cls=org.springframework.core.log.LogAccessor,applog.mthd=error,applog.line=149,applog.msg=Stopping container due to an Error,exc.stack=java.lang.NoSuchFieldError: LIFTER\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.getLifterName(ReactorHooksHelper.java:171)\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.isTraceContextPropagator(ReactorHooksHelper.java:175)\n\tat org.springframework.cloud.sleuth.instrument.reactor.ReactorHooksHelper.shouldDecorate(ReactorHooksHelper.java:121)\n\tat reactor.core.publisher.Operators$LiftFunction.apply(Operators.java:2488)\n\tat reactor.core.publisher.Operators$LiftFunction.apply(Operators.java:2449)\n\tat reactor.core.publisher.Flux.onAssembly(Flux.java:9692)\n\tat reactor.core.publisher.Flux.fromIterable(Flux.java:1118)\n\tat com.org.listener.MyListener.listen(MyListener.java:32)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n\tat java.lang.reflect.Method.invoke(Method.java:498)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:169)\n\tat org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:119)\n\tat org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:56)\n\tat org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:339)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.invoke(BatchMessagingMessageListenerAdapter.java:180)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:172)\n\tat org.springframework.kafka.listener.adapter.BatchMessagingMessageListenerAdapter.onMessage(BatchMessagingMessageListenerAdapter.java:61)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchOnMessage(KafkaMessageListenerContainer.java:2268)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessageWithRecordsOrList(KafkaMessageListenerContainer.java:2258)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchOnMessage(KafkaMessageListenerContainer.java:2204)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeBatchListener(KafkaMessageListenerContainer.java:2114)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeBatchListener(KafkaMessageListenerContainer.java:1997)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:1976)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeIfHaveRecords(KafkaMessageListenerContainer.java:1364)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1355)\n\tat org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1247)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java)\n\tat java.lang.Thread.run(Thread.java:748)\n
I tried checking the reactor-core ReactorHooksHelper.java file, but field LIFTER seems to be present there. Need help to understand why service is giving this error.
Looks like issue with reactor. Which version of reactor-core are you having? For spring-boot version 2.6.6 try using reactor-core version 3.4.16
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.4.16</version>
</dependency>
You shouldn't specify a version for reactor-core. Spring-boot-dependencies takes care of that for you and would automatically use 3.4.16 of reactor-core. That's the beauty of using Spring Boot.
Check out this POM file
https://search.maven.org/artifact/org.springframework.boot/spring-boot-dependencies/2.6.6/pom
and search for <reactor-bom.version> and notice that the version is 2020.0.17.
After that, find the equivalent reactor-bom file
https://search.maven.org/artifact/io.projectreactor/reactor-bom/2020.0.17/pom
and notice that the version for reactor-core is 3.4.16
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.4.16</version>
</dependency>

Upgrading To Spring Boot 2.4.0 Breaks Legacy Applications

I'm upgrading a set of legacy applications to Spring Boot 2.4.0, running on OpenJDK 8, deployed to Pivotal Cloud Foundry.
The app and all its unit tests ran perfectly under Spring 2.3.4-RELEASE before I started this upgrade.
There was work to be done right off the bat: Spring Boot 2.4.0 brings in JUnit 5.x, so I had to fix all the JUnit 4.x tests to use the new annotations and classes.
After fixing all the tests I tried to run in IntelliJ 2020.2. All the tests failed, for the same reason: java.lang.IllegalStateException: Failed to load ApplicationContext. The root of the stack trace gives this cause:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
They removed a fundamental class from Spring Boot for the sake of Kubernetes, from the sound of it. I'm not sure I see why.
I did a Google search and found this explanation and fix.
I added spring.config.use-legacy-processing to my application.yml and a test application.properties file:
spring:
config:
use-legacy-processing: true
Still no joy - all the tests fail.
I'm confused by other links I've seen. Is this an issue with spring-cloud-dependencies? I'm reading that there might an issue with the Hoxton version. Do I need to add it to my app? It never needed this dependency before the upgrade:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
The problem is bigger than the tests. If I ignore them and try to run the app I still fail:
ERROR [main]: Application run failed |ApplicationName=Risk_Advisor | sourcedfrom=ERROR
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [sun.misc.Launcher$AppClassLoader#18b4aac2]
The root cause is the same:
java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
when ever you do upgrades on spring, pls always look at the spring / cloud compatibility matrix and then upgrades the versions for both spring and cloud accordingly:
Also, pls note that you may not have added spring cloud as direct dependency but it may be coming into your final jar as a transitive dependency so its always better to add below spring cloud dependency as direct dependency management in your pom to stay away from any conflicts:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
I got the same error when migrating to Spring Boot 2.4.4 which forced me to migrate to Spring Cloud 2020.0.1 as well. In my case, the error was due to Bootstrap, provided by spring-cloud-commons, not being any longer enabled by default. I had to re-enabled it by adding the following new starter in my build.gradle file as stated here:
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'
You say your app doesn't use Spring Cloud, so I'm not sure why you ended up facing which seems to be the same issue. Hopefully this workaround might work for you and help out others using Spring Cloud.
To fix the failing JUnit 4 tests, I have just added it as a dependency:
testImplementation 'junit:junit:4.13'
I had the same error for JUnit 4 tests after migration my project to Spring Boot 2.5.6. Adding JUnit 4 dependencies did not fix this error as well as migration JUnit 4 tests to JUnit 5. My project does not define Spring Cloud dependencies in build.gradle so in order to find where those dependencies come from I simply ran gradle command:
gradle dependencyInsight --dependency org.springframework.cloud
and saw that spring cloud dependencies were pulled within one of the custom libraries. Upgrade spring cloud dependencies to a compatible version there and reimport custom library fixed the error.

spring-boot-security 2.2.5 - java.lang.NoClassDefFoundError:org/bouncycastle/crypto/params/Argon2Parameters

I am using spring boot security version 2.2.5.RELEASE in that , I am creating a custom password encoder with Argon2PasswordEncoder as my password encoder.
In this when i run, can see following error in the Argon2PasswordEncoder.java where i can see these two imports are missing,
import org.bouncycastle.crypto.generators.Argon2BytesGenerator;
import org.bouncycastle.crypto.params.Argon2Parameters;
Error:
java.lang.NoClassDefFoundError: org/bouncycastle/crypto/params/Argon2Parameters$Builder
at org.springframework.security.crypto.argon2.Argon2PasswordEncoder.encode(Argon2PasswordEncoder.java:78) ~[spring-security-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at com.custom.CustomPasswordEncoder.encode(CustomPasswordEncoder.java:11)
Please suggest me want to do, am I missing some dependency or its the spring boot version issue. And also how to overcome.
Many thanks.
I got the issue. for the version 2.2.5 springboot we need to explicitly add the dependency for Argon2BytesGenerator, Argon2Parameters nt found issue, since its not included in this version.
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.64</version>
</dependency>

Versioning issue when using jersey 2.9 with tomcat7 + java8

We have a maven project to develop a jersey 2.0 REST service, on Eclipse (kepler)
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.9.1</version>
</dependency>
In conjunction with:
java8
tomcat7
When deploying the web application (using $ mvn install && mvn -X tomcat7:redeploy) we get the below exception:
Caused by: java.lang.UnsupportedClassVersionError: org/glassfish/jersey/servlet/init/JerseyServletContainerInitializer : Unsupported major.minor version 51.0 (unable to load class org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2840)
I examined the MANIFEST file in the org.glassfish.jersey.containers jar, and (as suspected) it says build on 1.7 JDK
Tomcat logs confirm that it uses java8 itself
We cannot move back to java8. Is there a way/hack we can get past this error?
From tomcat 7.0.26, I upgraded to next version > Tomcat 7.0.47, to see if that helps.
Things started working magically. Deployed app successfully
Would be glad if someone can explain how the same plugin started to ignore jdk versions, just due to a change in tomcat version.

Which spring-test jar version to use with Spring Integration

We are using Spring Integration version 2.2.0.RC2.
When running tests, the following exception is thrown:
java.lang.IncompatibleClassChangeError: org/springframework/core/type/classreading/AnnotationMetadataReadingVisitor
I understand this is because of a clash of Spring jars, likely due to the wrong version in the following maven dependency
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.2.2.RELEASE</version>
</dependency>
When using Spring Integration version 2.2.0.RC2, which version of spring-tests should be used? Furthermore, what is the best way to resolve these kind of Maven clashes in future - is there a listing of compatible versions of Spring jars?
Thanks
If you a do a mvn dependency:tree are there any org.springframework:spring-core libraries in there that are not at the expected levels?
Run that and make sure your spring version numbers are ALL consistent. Use dependencyManagement stanzas to ensure they're consistent.
This issue had the same symptoms.
We run a nightly build of SI against Spring 3.2.x; 3.1.3 is simply the minimum supported dep. To use a newer version of Spring, you can <exclude/> the transitive dependencies in your POM.

Resources