How to define constant in jboss drools?

我是研究僧i 提交于 2019-12-10 20:39:39

问题


All

I want to know that how to define contant variable in jboss drools rule.

So, Admin has to change only one place to modify the configurable value.

Thanks.


回答1:


You´re able to define global variables within a rule. This variable can be filled via Java like this:

public void init() {
        StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession();

        String string = "foo";
        // setGlobal 'string' as 'var' in rule
        ksession.setGlobal("var", string);
}

In the rule, this global can be accessed via the 'global' keyword:

global String var;

rule "Test"
    when
        # actual condition 
    then
        # RHS
end


来源:https://stackoverflow.com/questions/6381650/how-to-define-constant-in-jboss-drools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!