I've had something similar on a different embedded kafka project. Most likely your issue is that you are putting kafka-clients 3.0.0 on the classpath alongside the Kafka server in version 2.7.1, which is the version brought in by your spring-kafka-test dependency. Since the Kafka server itself depends on kafka-clients, if you upgrade kafka-clients but not the server on the same classpath, you might get code mismatches like this.
I think you need to wait for a new version of spring-kafka-test. You can try bumping the org.apache.kafka:kafka_2.13 dependency to 3.0.0, but there's no guarantee it will work. Den fre. 24. sep. 2021 kl. 09.24 skrev Bruno Cadonna <cado...@apache.org>: > Hi Bruce, > > I do not know the specific root cause of your errors but what I found is > that Spring 2.7.x is compatible with clients 2.7.0 and 2.8.0, not with > 3.0.0 and 2.8.1: > > https://spring.io/projects/spring-kafka > > Best. > Bruno > > On 24.09.21 00:25, Chang Liu wrote: > > Hi Kafka users, > > > > I start running into the following error after upgrading `Kafka-clients` > from 2.5.0 to 3.0.0. And I see the same error with 2.8.1. I don’t see a > working solution by searching on Google: > https://stackoverflow.com/questions/46914225/kafka-cannot-create-embedded-kafka-server > < > https://stackoverflow.com/questions/46914225/kafka-cannot-create-embedded-kafka-server > > > > > > This looks like backward incompatibility of Kafka-clients. Do you happen > to know a solution for this? > > > > ``` > > java.lang.NoSuchFieldError: DEFAULT_SASL_ENABLED_MECHANISMS > > > > at kafka.server.Defaults$.<init>(KafkaConfig.scala:242) > > at kafka.server.Defaults$.<clinit>(KafkaConfig.scala) > > at kafka.server.KafkaConfig$.<init>(KafkaConfig.scala:961) > > at kafka.server.KafkaConfig$.<clinit>(KafkaConfig.scala) > > at kafka.server.KafkaConfig.LogDirProp(KafkaConfig.scala) > > at > org.springframework.kafka.test.EmbeddedKafkaBroker.afterPropertiesSet(EmbeddedKafkaBroker.java:298) > > at > org.springframework.kafka.test.rule.EmbeddedKafkaRule.before(EmbeddedKafkaRule.java:113) > > at > org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:50) > > at org.junit.rules.RunRules.evaluate(RunRules.java:20) > > at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) > > at org.junit.runners.ParentRunner.run(ParentRunner.java:413) > > at org.junit.runner.JUnitCore.run(JUnitCore.java:137) > > at > com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) > > at > com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) > > at > com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221) > > at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) > > ``` > > > > I got some suggestion that is to upgrade Spring library. > > > > This is the `pom.xml` that defines all my dependencies. I only upgraded > the `Kafka-clients` in production: > https://github.com/opensearch-project/security/blob/main/pom.xml#L84 < > https://github.com/opensearch-project/security/blob/main/pom.xml#L84> > > > > The dependency for test still remains: > https://github.com/opensearch-project/security/blob/main/pom.xml#L503 < > https://github.com/opensearch-project/security/blob/main/pom.xml#L503> > > > > Is this the Spring library that should be upgraded? > https://github.com/opensearch-project/security/blob/main/pom.xml#L495 < > https://github.com/opensearch-project/security/blob/main/pom.xml#L495> > > > > But even though I upgraded Spring library to 2.7.7: > https://github.com/opensearch-project/security/blob/main/pom.xml#L496 < > https://github.com/opensearch-project/security/blob/main/pom.xml#L496> , > I got another error: > > > > `java.lang.NoClassDefFoundError: > org/apache/kafka/common/record/BufferSupplier` > > > > Any suggestion helping me out this will be highly appreciated! > > > > Thanks, > > Bruce > > >