'Why Kafka Producer call Failed to introspect Class

I haven't enough expirience in Java and, especially in Kafka. I tried to use a baeldung guide and this what i have now as a Config:

@Configuration
public class KafkaProducerConfig {

 @Value(value = "${kafka.boostrapAddress}")
 private String bootstrapAddress;

 @Bean
 public KafkaTemplate<String, String> kafkaTemplate() {
    return new KafkaTemplate<>(producerFactory());
 }

 @Bean
 public ProducerFactory<String, String> producerFactory() {
     Map<String, Object> configProps = new HashMap<>();
     configProps.put(
            ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
            bootstrapAddress);
     configProps.put(
            ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
            StringSerializer.class);
     configProps.put(
            ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
            StringSerializer.class);
     return new DefaultKafkaProducerFactory<>(configProps);
 }
}

And what I have in Util class for my autotests:

@Component
public class KafkaUtil {

 @Autowired
 private KafkaTemplate<String, String> kafkaTemplate;

 public void sendMessage(String topicName, String msg) {
    kafkaTemplate.send(topicName, msg);
 } 

And now my tests:

@SpringBootTest(classes = CucumberSpringConfig.class)

public class ByKafka {
 private KafkaUtil kafkaUtil;

 private static final String topicName = "mytopic";

 @Autowired
 public ByKafka(KafkaUtil kafkaUtil) {
    this.kafkaUtil = kafkaUtil;
 }

 @Когда("тесткафка")
 public void sendTestMessage() {
    kafkaUtil.sendMessage(topicName, "hello");
 }

}

When I tried to run this test, i give next error:

java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@2437c6dc] at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:737) ~[spring-core-5.3.2.jar:5.3.2] at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:702) ~[spring-core-5.3.2.jar:5.3.2] at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:687) ~[spring-core-5.3.2.jar:5.3.2] at...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source