简体   繁体   English

在DROOLS中动态加载规则

[英]Dynamic loading of rules in DROOLS

I am new to drools. 我是流口水的新手。 I just want to understand how to dynamically update rules at run time. 我只想了解如何在运行时动态更新规则。 Considering Drools - Ability to define rules at runtime? 考虑Drools-是否能够在运行时定义规则?

I wrote a code: 我写了一个代码:

 while(true){
    session = fetchStatefulSession();//Some method to get drools session
    system.out.println("enter text");
    //Some code to read input
    session.fireAllrules();
 }

Now by the time I give input I have updated .drl rules file. 现在,当我输入信息时,我已经更新了.drl规则文件。 Even after that the result is same on, 即使结果相同

 session.fireAllrules();

as it was earlier. 和以前一样。 That is the changes in rules are not reflected. 那就是规则的变化没有体现出来。

I am not sure is this proper way to use, dynamic loading of rules. 我不确定这种正确的使用方式是动态加载规则。 Please suggest me 请建议我

Thanks Chakri 谢谢查克里

Your code is only getting the session which is still using the same .drl file. 您的代码仅获得仍使用相同.drl文件的会话。 Your code needs to include loading the .drl files as well. 您的代码还需要包括加载.drl文件。

knowledgeBuilder.add(ResourceFactory.newClassPathResource(rulesFile, YourClass.class), ResourceType.DRL);

But still I doubt it will work or not because loading files at run time is very prone to error and difficult to maintain. 但是我仍然怀疑它是否会起作用,因为在运行时加载文件非常容易出错并且难以维护。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM