spring 类型的对象上找不到属性或字段“processEvent”

zdwk9cvp  于 2023-05-27  发布在  Spring
关注(0)|答案(1)|浏览(168)

Spring4.3
POJO

public final class ProcessEvent {
    private int id;
    private String requestId;
 
    public ProcessEvent(int id, String requestId) {
        this.id = id;
        this.requestId = requestId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }
}

我只想在“processEvent.getRequestId() != null“时调用方法handleProcessEvent。我试试这个

@Async
@EventListener(condition = "processEvent.getRequestId() != null")
public void handleProcessEvent(ProcessEvent processEvent) {
...
}

但我得到错误:

2023-05-25 21:58:32.031 ERROR [AbstractProcessStep:SimpleAsyncTaskExecutor-6] Error occurred at process: 4566 step: 3 action: next step
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'processEvent' cannot be found on object of type 'org.springframework.context.event.EventExpressionRootObject' - maybe not public or not valid?
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:229) ~[spring-expression-4.3.22.RELEASE.jar:4.3.22.RELEASE]
        at org.springframework.expression
2nbm6dog

2nbm6dog1#

这是spel的表达。像这样的东西应该能用

@EventListener(condition = "#{processEvent.getRequestIId() != null}")

@EventListener(condition = "#processEvent.getRequestIId() != null")

相关问题