I am trying to follow https://github.com/spring-projects/spring-kafka/issues/361 to pass topic names from .yml file to the @kafkalistener. But the compiler throws following error
Type mismatch.
Required:
Array<String>
Found:
String
Unresolved reference: spring
Below is the receiver code
@Component
class Receiver {
companion object {
private val LOGGER = LoggerFactory.getLogger(Receiver::class.java)
}
@Autowired
private val taskExecutor: TaskExecutor? = null
@Autowired
private val applicationContext: ApplicationContext? = null
@KafkaListener(topics = "#{'${spring.kafka.topics}'.split(',')}")
fun receive(@Header(KafkaHeaders.RECEIVED_TOPIC) topic: String) {
}
}
Below is my build.gradle file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "2.1.7.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
kotlin("jvm") version "1.2.71"
kotlin("plugin.spring") version "1.2.71"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.kafka:spring-kafka")
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
What am i missing here?