user9233229
user9233229

Reputation:

How can I set global variable in drools using drools-spring and use same in DRL file

Basically I want to store a class reference as global variable from spring service class and use the same inside the DRL file to access method and properties of global reference.

Upvotes: 1

Views: 3390

Answers (2)

jeet427
jeet427

Reputation: 596

Inside your service class use below code:

StatelessKnowledgeSession knowledgeSession;
CustomClass reference;
knowledgeSession.setGlobal("global1", reference);
knowledgeSession.execute(fact);

Inside DRL file

import CustomClass;

global CustomClass global1

Use reference inside any rule.

Upvotes: 2

Nelson Christos
Nelson Christos

Reputation: 67

you have to set the object ref into the kieSession as below

kieSession.setGlobal("serviceName", serviceRef);

and in your drools file import the global reference

global com.example.Service serviceName

Upvotes: 2

Related Questions