title: Spring Boot: read from yaml using @ConfigurationProperties not working with @Data
body: <p>I am trying to retrieve value from application.yml. The final line below is showing kafkaConfig as null, and cannot read. How do I setup the Kafka Config and code properly, to read from the json file? We are using @Data instead of getters/setters.</p>
  <p><strong>KafkaConfig.java</strong></p>
  <pre><code>@Configuration
  @ConfigurationProperties(&quot;kafka&quot;)
  @Data
  public class KafkaConfig {
      private String topic;
      private String event;
  }
  </code></pre>
  <p><strong>Application.yml</strong></p>
  <pre><code>kafka:
    topic: &quot;testTopic&quot;
    event: &quot;testEvent&quot;
  </code></pre>
  <p><strong>KafkaProducerBeans.java</strong></p>
  <pre><code>@Component
  public class KafkaProducerBeans {
  
      @Autowired
      private KafkaConfig kafkaConfig;
  
      public KafkaProducerBeans(KafkaConfig kafkaConfig) {
          this.kafkaConfig = kafkaConfig;
      }
  
      @Bean(name = &quot;kafkaTestClient&quot;)
      public String getData() {
          return kafkaConfig.getTopic();  // final line is creating null for kafka Config
      }
  </code></pre>
  <p>Resource: <a href="https://codingnconcepts.com/spring-boot/spring-configuration-properties-using-yml/" rel="nofollow noreferrer">https://codingnconcepts.com/spring-boot/spring-configuration-properties-using-yml/</a></p>