概述
Using a Global variable to log information
In the code we just did, we wrote the code System.out.println(“blabla”). This is fine but let us imagine you want to log somewhere else, it is not possible. One good practice is to use global variables for that purpose. We first define a java class called OutputDisplay that we shall create in the util package in src/main/java
Now we shall update the lesson1.drl file
The keyword global is used and then a normal java declaration. Here the global is of type OutputDisplay and the variable is called showResults. This variable can now be used in the “them” part of the rule as here.
To initialize the global variable, we shall use the method “setGlobal” on the session we create as shown here in our test :
When running the Junit test, the console should look like this :
最后
以上就是耍酷画笔为你收集整理的Drools Using a Global variable to log information的全部内容,希望文章能够帮你解决Drools Using a Global variable to log information所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复