2014-10-16 99 views
0

我試圖用Esper運行一個簡單的測試(第14章,http://dl.e-book-free.com/2013/07/activiti_in_action.pdf)。該代碼非常簡單:Esper:EPL「選擇」失敗du驗證錯誤

public class EventLengthWindowTest { 
    public class LoanRequestEvent { 
    public int amount =2; 

    public LoanRequestEvent(int a){ 
     amount += a; 
    } 
} 

private int sumAmount = 0; 

@Test 
public void testEventLengthWindow() { 
    Configuration configuration = new Configuration(); 
    configuration.addEventType(LoanRequestEvent.class); 

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); 
    EPAdministrator admin = epService.getEPAdministrator(); 
    EPStatement epStatement = admin.createEPL("select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)"); 

    ... 
} 

我得到關於EPL部分的錯誤消息:

"select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)" 

它說:

com.espertech.esper.client.EPStatementException: Error starting statement: Failed to validate select-clause expression 'sum(amount)': Property named 'amount' is not valid in any stream [select sum(amount) as sumAmount from LoanRequestEvent.win:length(2)] 

任何想法,爲什麼出現這種情況?

回答

2

如果您希望Esper讀取和/或寫入它們,您需要爲事件類中的事件屬性提供JavaBean getter和setter。對於你的例子工作,你需要添加一個像這樣的吸氣:

public class LoanRequestEvent { 
    public int amount =2; 

    public LoanRequestEvent(int a){ 
     amount += a; 
    } 

    public int getAmount() { 
     return amount; 
    } 
} 
+0

太好了,非常感謝! – KayJ 2014-10-17 07:40:05