spring-projects / spring-kafka

Provides Familiar Spring Abstractions for Apache Kafka
https://projects.spring.io/spring-kafka
Apache License 2.0
2.19k stars 1.56k forks source link

Code example in the documentation for Dynamically Creating Containers - Prototype Beans (Kotlin) is wrong #3513

Closed mohamedmelfiky closed 1 month ago

mohamedmelfiky commented 1 month ago

Spring Kafka 3.2.4

In the documentation for Dynamically Creating Containers - Prototype Beans (Kotlin) the example throw exception. It should be as follow instead

  class MyPojo(val id: String, val topic: String) {

      @KafkaListener(id = "#{__listener.id}", topics = ["#{__listener.topic}"])
      fun listen(`in`: String?) {
          println(`in`)
      }

  }

  @Bean
  @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
  fun pojo(id: String, topic: String): MyPojo {
      return MyPojo(id, topic)
  }

  applicationContext.getBean(MyPojo::class.java, "one", "topic2")
  applicationContext.getBean(MyPojo::class.java, "two", "topic3")

Link to the above mentioned documentation paragraph:

https://docs.spring.io/spring-kafka/reference/kafka/dynamic-containers.html#prototype-beans

artembilan commented 1 month ago

The contribution is welcome: https://github.com/spring-projects/spring-kafka/blob/main/CONTRIBUTING.adoc!