如何在Java中动态构建Drools规则?
如何在Java中动态构建Drools规则而不是提供静态drl文件?
我在 xml 中定义了一组匹配规则,我需要解析这些规则并能够在运行时重新加载它。有没有办法动态构建Drools规则?在文档中找不到它。
How to build Drools rules in Java dynamically instead of providing static drl file?
I have a set of matching rules defined in xml that I need to parse and be able to reload it in runtime. Is there any way to build Drools rules dynamically? Couldn't find it in the docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意罗曼的评论 - 如果你有某种声明形式的规则 - 你可以直接从中生成代码 - 除非这些规则中隐含着更高阶的逻辑(我不太可能发现),或者也许你想做一个从 XML 迁移到规则语言的时间。
I agree with Romain's comment - if you have the rules in some declarative form - you could just generate code directly from that - unless there is higher order logic implicit in those rules (unlikely I have found), or perhaps you want to do a one time migration to a rule language out of the XML.
我同意以前的答案和评论,即规则被修改为“静态”部分。当规则是按需动态创建时,规则引擎的使用是有问题的。然而,在某些情况下,规则并未以 drools 可以立即处理的形式/格式提供。在这种情况下,需要在初始化阶段以编程方式创建规则。
说了这么多,下面是如何向 drools 添加规则(以字符串形式给出)。
I agree with former answers and comments that rules are ment to be the "static" part. When rules are created dynamically on demand, the usage of a rules engine is questionable. However, there are cases where rules are not provided in form / format that drools can handle out of the box. In such cases programmatical creation of rules during the initialization phase is needed.
These things said, here is how you can add a rule (given as a String) to drools.