Prakash Gopinathan
Prakash Gopinathan

Reputation: 11

KafkaListener not resolving containerFactory with "#{__listener.getContainerFactory()}"

I am using the following methods to get the KafkaListener properties. But it does not resolve the containerFactory value. But it works for topics and groupId.

@KafkaListener(topics = "#{__listener.getTopics()}",
            groupId = "#{__listener.getGroupId()}",
            containerFactory =  "#{__listener.getContainerFactory()}")
    public void sampleTestTopicListener(@Payload byte[] data,

.....
 @Value("sampleTestListenerContainerFactory")
    private String containerFactory ;

    public String  getContainerFactory(){
        return containerFactory;
    }
....
Spring-kafka-2.2.5.RELEASE 

I get the following error :
A component required a bean named '#{__listener.getContainerFactory()}' that could not be found.

Changing the containerFactory value to "sampleTestListenerContainerFactory" instead of spEL, it works fine.

How can I set it using the current beans property?

Upvotes: 1

Views: 1473

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

The containerFactory option on that @KafkaListener annotation cannot be as a SpEL expression. You can use a property placeholder resolution though. Like this:

containerFactory = "${sampleTestListenerContainerFactory}"

but it is better to use a real bean name anyway: the KafkaListenerContainerFactory really must be a bean...

Another note: the version of Spring for Apache Kafka 2.2.5 is out of support. It has reached its End of Life long time ago. It is more practical to stay with the latest versions: https://spring.io/projects/spring-kafka#learn

Upvotes: 1

Related Questions