I'm trying to create a Bean named "Kafka" with a custom constructor that takes PropertiesFileUtils.KAFKA_HOST
and PropertiesFileUtils.KAFKA_PORT
as parameters. However, during the compilation process, I encountered the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project businessServer: Compilation failure
[ERROR] /C:/Users/cheny/Desktop/NewsRecommender-Main/backend/businessServer/src/main/java/com/tqz/business/utils/Configure.java:[25,44] cannot find symbol
[ERROR] symbol: constructor Kafka(java.lang.String,java.lang.Integer)
[ERROR] location: class kafka.Kafka
[ERROR]
[ERROR] -> [Help 1]
Here's the code snippet:
@Bean(name = "Kafka")
public Kafka getKafkaClient() {
return new Kafka(PropertiesFileUtils.KAFKA_HOST, PropertiesFileUtils.KAFKA_PORT);
}
I have confirmed that the values of PropertiesFileUtils.KAFKA_HOST
and PropertiesFileUtils.KAFKA_PORT
are correct. I have checked the relevant dependencies and made sure that the correct Kafka class is imported into the project. However, I'm still unable to resolve this issue.
I'm using the following environment and tools:
- Java 8
- Maven 3.5
pom.xml
<dependencies>
<!-- other dependencies -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.12</artifactId>
<version>1.1.1</version>
</dependency>
<!-- other dependencies -->
</dependencies>
I have tried the following solutions without success:
- Ensuring that the Kafka dependencies are correctly added to the Maven project.
- Cleaning and rebuilding the project.
- Verifying that the types and order of constructor parameters match the definition of the Kafka class.
I'm looking for a solution to fix this error and successfully create the Kafka instance. Any help would be greatly appreciated!
There are many docs about how to use kafka-client. Not sure if you are following some tutorial. Here you have a couple of them
Confluent - kafka client: this one will explain how to use it in just a java project without any framework
Spring - kafka client: here you have a tutorial that shows how to use kafka client together with spring
Baeldung - spring with kafka client: an article from Baeldung. Great blog with many tutorials for different things