How to define a constant in joboss drools?

All

I want to know how to define a constant variable in a joboss drools rule.

So, the administrator only needs to change one place in order to change the custom value.

Thank.

+3
source share
1 answer

You can define global variables inside a rule. This variable can be populated through Java as follows:

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

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

In a rule, this global access can be accessed through the global keyword:

global String var;

rule "Test"
    when
        # actual condition 
    then
        # RHS
end
+4
source

All Articles