本文介绍了在2个单独的kbase/ksessions中使用具有共同功能的Drools drl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Drools 6.2.0.Final,我们有一个rules项目,其中在kmodule.xml中配置了2个单独的kbase和ksessions:

using Drools 6.2.0.Final we have a rules project with 2 separate kbases and ksessions configured like this in the kmodule.xml:

<kbase name="kbase1"
      packages="foo.bar.package1">
    <ksession name="ksession1" type="stateless" />
</kbase>

<kbase name="kbase2"
        packages="foo.bar.package2">
  <ksession name="ksession2" type="stateless" />
</kbase>

在每个软件包中,我们都有许多包含某些业务规则的.drl文件.除了这些包之外,每个包还包含一个.drl,其中包含从业务规则文件中调用的功能,例如package1-functions.drl和package2-functions.drl.由于这两个功能文件的内容相同,因此我们正在考虑创建一个通用"程序包,并且仅具有功能文件的一个副本.

In each of these packages we have a number of .drl files that contain some business rules.In addition to those each package contains a .drl containing functions that are called from the business rules files, e.g. package1-functions.drl and package2-functions.drl.Since the content of these 2 function files is identical we are thinking about creating a "common" package and have only one copy of the functions file.

但是,我们还没有设法使规则与单独的程序包中的功能一起使用.

However, we have not managed to get our rules to work with the functions being in a separate package.

这是我们配置kmodule.xml的方式:

This is how we configured our kmodule.xml:

<kbase name="common"
    packages="foo.bar.common"/>

<kbase name="kbase1" includes="common"
    packages="foo.bar.package1">
    <ksession name="ksession1" type="stateless" />
</kbase>

<kbase name="kbase2" includes="common"
       packages="foo.bar.package2">
    <ksession name="ksession2" type="stateless" />
</kbase>

我们尝试的另一种方法是不使用通用" kbase,而是将通用包添加到kbase1和kbase2的"packages"属性中.

Another way we tried was without a "common" kbase but adding the common package to the "packages" attribute in kbase1 and kbase2.

是否可以在其他2个kbase中使用通用软件包?

Is it possible to use a common package within 2 other kbases?

推荐答案

无法从其他DRL包中使用DRL函数.

There is no way a DRL function can be used from another DRL package.

在单独的DRL文件中可以具有一个或多个功能,并且可以在同一DRL包中的任何DRL文件中使用它们.

It is possible to have one or more functions on a separate DRL file, and they can be used in any DRL file that is in the same DRL package.

也许您是在高估DRL软件包的重要性-如果所有DRL文件都在同一个DRL软件包中,则不会有任何问题.

Perhaps you are overrating the importance of DRL packages - you won't have any problems if all DRL files are in the same DRL package.

或者,考虑使用Java静态方法.

Alternatively, consider the use of Java static methods.

这篇关于在2个单独的kbase/ksessions中使用具有共同功能的Drools drl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 02:03