java.lang.NoSuchMethodError on Kafka Consumer with spring-kafka 2.1.0 and SpringBoot 1.5.9
Asked Answered
I

2

15

I am trying to setup Kafka Consumer using SpringBoot(1.5.9) and Spring-kafka(2.1.0). However when I start my app I get java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V on Kafka MessagingMessageListenerAdapter. I tried with Spring-Kafka(1.2.0) and that error went away. Has anyone else experienced this version incompatibility?

Here is my config class

@EnableKafka
@Configuration
public class ImporterConfigs{

static Logger logger = Logger.getLogger(ImporterConfigs.class);

@Value("${kafka.bootstrap-servers}")
private static String bootstrapServers;

@Bean
public Map<String, Object> consumerKafkaConfigs() {
  Map<String, Object> props = new HashMap<>();
  // list of host:port pairs used for establishing the initial connections to the Kakfa cluster
  props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
  props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
  props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
  // allows a pool of processes to divide the work of consuming and processing records
  props.put(ConsumerConfig.GROUP_ID_CONFIG, "test-consumer-group");

  return props;
}

@Bean
public ConsumerFactory<String, String> consumerFactory() {
  return new DefaultKafkaConsumerFactory<>(consumerKafkaConfigs());
}

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory =
            new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());


  return factory;
}

}

Here is the full stacktrace:

java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)V
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.determineInferredType(MessagingMessageListenerAdapter.java:396) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.<init>(MessagingMessageListenerAdapter.java:100) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.<init>(RecordMessagingMessageListenerAdapter.java:61) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.MethodKafkaListenerEndpoint.createMessageListenerInstance(MethodKafkaListenerEndpoint.java:172) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.MethodKafkaListenerEndpoint.createMessageListener(MethodKafkaListenerEndpoint.java:132) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.AbstractKafkaListenerEndpoint.setupMessageListener(AbstractKafkaListenerEndpoint.java:338) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.AbstractKafkaListenerEndpoint.setupListenerContainer(AbstractKafkaListenerEndpoint.java:323) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.AbstractKafkaListenerContainerFactory.createListenerContainer(AbstractKafkaListenerContainerFactory.java:227) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.AbstractKafkaListenerContainerFactory.createListenerContainer(AbstractKafkaListenerContainerFactory.java:49) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistry.createListenerContainer(KafkaListenerEndpointRegistry.java:183) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistry.registerListenerContainer(KafkaListenerEndpointRegistry.java:155) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistry.registerListenerContainer(KafkaListenerEndpointRegistry.java:129) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistrar.registerAllEndpoints(KafkaListenerEndpointRegistrar.java:138) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.config.KafkaListenerEndpointRegistrar.afterPropertiesSet(KafkaListenerEndpointRegistrar.java:132) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(KafkaListenerAnnotationBeanPostProcessor.java:229) ~[spring-kafka-2.1.0.RELEASE.jar:2.1.0.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:781) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
at com.vitechinc.springbootapplication.V3MessageImporterApplication.main(V3MessageImporterApplication.java:25) [classes/:na]
Immutable answered 20/12, 2017 at 18:26 Comment(3)
you are not providing any code examples that we could run to help you.Gendarmerie
@Gendarmerie The question is more about the version compatibility and not codeImmutable
nice edit. it makes it conform to site standards.Gendarmerie
D
28

The Spring-kafka 2.1 is based on the Spring Framework 5.0 and that is exactly what you see with that error:

java.lang.NoSuchMethodError: org.springframework.util.Assert.state(ZLjava/util/function/Supplier;)

Spring Framework 4.3 (the foundation for Spring Boot 1.5) doesn't support Java 8 yet.

You should consider to switch to Spring Boot 2.0 or stick with the Spring Kafka 1.3.2 which is compatible with Boot 1.5 background and can be reconfigured for Apache Kafka 1.0 Client.

Desirae answered 20/12, 2017 at 19:1 Comment(3)
Thanks. That is what I wanted to confirmImmutable
weird, because they're stating that Spring Framework 4.3.x supports JDK 6-8 github.com/spring-projects/spring-framework/wiki/…Demesne
That’s right, you can use any Java you need, but the framework code base can’t use language features higher than 6 in that case.Desirae
R
0

In my case I had a weird maven version mismatch between the mvn used by IntelliJ (invalid/old version -> deprecated /.m2/repository) and mvn on the commandline (3.9.0)

Retaliate answered 21/3, 2023 at 10:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.