以下代码行直接来自文档
ksession.addEventListener(new DebugWorkingMemoryEventListener());
在eclipse中提示以下错误
方法中的addEventListener(WorkingMemoryEventListener)方法 WorkingMemoryEventManager不适用于参数 (DebugWorkingMemoryEventListener)
答案 0 :(得分:1)
您可能导入org.drools.event.DebugWorkingMemoryEventListener
而不是org.drools.event.rule.DebugWorkingMemoryEventListener
。
在我们的例子中,以下代码可以正常工作:
import org.drools.event.rule.DebugWorkingMemoryEventListener;
import org.drools.event.rule.ObjectInsertedEvent;
import org.drools.event.rule.ObjectRetractedEvent;
import org.drools.event.rule.ObjectUpdatedEvent;
...
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
ksession.addEventListener(new DebugWorkingMemoryEventListener() {
@Override
public void objectInserted(ObjectInsertedEvent event) {
System.out.println(event);
}
@Override
public void objectRetracted(ObjectRetractedEvent event) {
System.out.println(event);
}
@Override
public void objectUpdated(ObjectUpdatedEvent event) {
System.out.println(event);
}
});