Skip to content

@PulsarListener Spring spel could not resolve beanRef #1169

@andy-ltluan

Description

@andy-ltluan

Hi @onobc
I tried to setup @PulsarListener like below:

@PulsarListener(topics = "#{__listener.getTopic()}",
            subscriptionName = "#{__listener.getSubscriptionName()}",
            subscriptionType = SubscriptionType.Failover)
    public void handleTaskSplitterMessage(Message<byte[]> message) {
        String taskName = message.getProperty(MessageTasks.HEADER_TASK_NAME);
        if (XStrings.hasText(taskName)) {
            try {
                taskManager.executeTaskSplit(taskName, message.getData());
            } catch (TaskException e) {
                LOG.error(e.getMessage(), e);
                throw e;
            } catch (RuntimeException e) {
                LOG.error("Failed to execute task split [taskName={}]", taskName, e);
                throw e;
            }
        } else {
            LOG.error("Received a message without task name");
        }
    }

    public String getTopic() {
        return messageTaskHelper.getTopic();
    }

    public String getSubscriptionName() {
        return messageTaskHelper.getSubscriptionName();
    }

When running test, I've got this error:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field '__listener' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
	at app//org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:229)
	at app//org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:112)
	at app//org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:100)
	at app//org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:60)
	at app//org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:96)
	at app//org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:116)
	at app//org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:273)
	at app//org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:182)
	... 48 more

After tried to understand the problem -> in PulsarListenerAnnotationBeanPostProcessor there is a private field called listenerScope which is used to pass to BeanExpressionContext.

The problem is there are 2 fields listenerScope, one in PulsarListenerAnnotationBeanPostProcessor and another one in AbstractPulsarAnnotationsBeanPostProcessor which PulsarListenerAnnotationBeanPostProcessor extended from.

When processPulsarListener executed -> the method calls this.listenerScope which private field in PulsarListenerAnnotationBeanPostProcessor, but I do think it should be listenerScope from AbstractPulsarAnnotationsBeanPostProcessor

So please correct me if I'm wrong this is a problem. I'm using Spring Pulsar 1.2.6

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions