spring-cloud-openfeign
spring-cloud-openfeign copied to clipboard
IllegalArgumentException, Could not find class error
I'm getting an error from StreamBridge when trying to send a message to a specific Kafka topic. Funny thing is that I only get this error sometimes. When I trigger the service manually it does not give any errors. I stuck with this error for a while
java.version = 17
org.springframework.boot = 2.6.4
spring-cloud.version = 2021.0.1
spring-cloud-starter-stream-kafka = 3.2.4
Code :
@Slf4j
@Service
@RequiredArgsConstructor
public class UpdateEventAdapter implements UpdateEventPort {
private final StreamBridge streamBridge;
@Async
@Override
public void instrumentUpdated(InstrumentUpdatedEvent instrumentUpdatedEvent) {
streamBridge.send(INSTRUMENT_UPDATED_PRODUCER, KafkaMessageBuilder.build(instrumentUpdatedEvent, instrumentUpdatedEvent.getUid()));
}
}
Trace:
va.util.concurrent.CompletionException: java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.condition.OnBeanCondition] at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[na:na] at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:320) ~[na:na] at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1770) ~[na:na] at util.TokenAwareRunnable.run(TokenAwareRunnable.java:28) ~[na:na] at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395) ~[na:na] at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[na:na] at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[na:na] at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[na:na] Caused by: java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.condition.OnBeanCondition] at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:334) ~[spring-core-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.ConditionEvaluator.getCondition(ConditionEvaluator.java:124) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:96) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:88) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:71) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.doRegisterBean(AnnotatedBeanDefinitionReader.java:254) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:147) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:137) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.context.annotation.AnnotationConfigApplicationContext.register(AnnotationConfigApplicationContext.java:168) ~[spring-context-5.3.16.jar!/:5.3.16] at org.springframework.cloud.stream.binder.DefaultBinderFactory.initializeBinderContextSimple(DefaultBinderFactory.java:410) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinderInstance(DefaultBinderFactory.java:265) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.binder.DefaultBinderFactory.doGetBinder(DefaultBinderFactory.java:223) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.binder.DefaultBinderFactory.getBinder(DefaultBinderFactory.java:151) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.binding.BindingService.getBinder(BindingService.java:389) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.binding.BindingService.bindProducer(BindingService.java:273) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.function.StreamBridge.resolveDestination(StreamBridge.java:282) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:210) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:164) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at org.springframework.cloud.stream.function.StreamBridge.send(StreamBridge.java:144) ~[spring-cloud-stream-3.2.2.jar!/:3.2.2] at com.getmidas.instrument.api.adapter.kafka.InstrumentUpdateEventAdapter.instrumentUpdated(InstrumentUpdateEventAdapter.java:24) ~[classes!/:0.0.1-SNAPSHOT] at com.getmidas.instrument.api.domain.service.StockService.sendInstrumentEvent(StockService.java:194) ~[classes!/:0.0.1-SNAPSHOT] at com.getmidas.instrument.api.domain.service.StockService.update(StockService.java:166) ~[classes!/:0.0.1-SNAPSHOT] at com.getmidas.instrument.api.domain.service.sync.instrument.tr.TrInstrumentSyncHelper.updateStock(TrInstrumentSyncHelper.java:92) ~[classes!/:0.0.1-SNAPSHOT] at com.getmidas.instrument.api.domain.service.sync.instrument.tr.TrInstrumentSyncHelper.syncHelper(TrInstrumentSyncHelper.java:36) ~[classes!/:0.0.1-SNAPSHOT] at com.getmidas.instrument.api.domain.service.sync.instrument.tr.TrInstrumentSyncService.lambda$syncCompletable$5(TrInstrumentSyncService.java:86) ~[classes!/:0.0.1-SNAPSHOT] at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[na:na] ... 7 common frames omitted Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.condition.OnBeanCondition at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[na:na] at java.base/java.lang.Class.forName0(Native Method) ~[na:na] at java.base/java.lang.Class.forName(Class.java:467) ~[na:na] at org.springframework.util.ClassUtils.forName(ClassUtils.java:284) ~[spring-core-5.3.16.jar!/:5.3.16] at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:324) ~[spring-core-5.3.16.jar!/:5.3.16]
Without a way to reproduce it there is no error, especially with CNFE on spring boot class which is at the core of everything. Any chance you can provide a sample that reproduces it?
I will try to reproduce the error, however when looking at the stack-trace, it is obvious that the ForkJoinWorkerThread in a Docker image built using the Spring Boot Build Image plugin seems to cause this error when trying to lazily initialize. The error seems to be strongly related to the Spring Boot Build Image, since using jib instead, does not cause this error.
The same is true for running the Docker image in certain Kubernetes environments, although not all environments seem to be affected.
Same problem happened with spring boot cloud openfeign, maybe it helps someway https://github.com/spring-cloud/spring-cloud-openfeign/issues/475
I'm facing the same problem when my application is running inside Docker. However, running the same code from the IDE works ...
Could you please create a small reproducible app with specific instructions to build and run?
I've should have been more precise in my explanation, I'm also facing
java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.condition.OnBeanCondition at
but in the context of spring-cloud-openfeign. But what is similar to the issue here is, that the problem does only appear when executing the application inside a Docker container. The same application running in the IDE works fine. The author of that issue provided a sample
As last user explained this issue only appears with the addition of open feign, hence the transfer of the issue
Fixed with https://github.com/spring-cloud/spring-cloud-commons/pull/1256.