【发布时间】:2019-07-31 09:19:18
【问题描述】:
我正在尝试从 drools 5 迁移到 drools 7。在版本 6 中,spring 集成发生了变化。基于documentationdrools:resources drools:resource 已被删除,但是我不知道如何使用新工具集实现相同的行为。我想要的是具有不同规则的不同 kiebase,这些规则在 drl 文件中定义。
documentation 表示可以使用包定义资源。不幸的是,在我的情况下,一个包可能包含多个 drl 文件,我想过滤其中一些。
我在 drools 5.x 中拥有的东西:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:drools-spring="http://drools.org/schema/drools-spring"
xsi:schemaLocation="http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<drools-spring:kbase id="rules1And3">
<drools-spring:resources>
<drools-spring:resource source="classpath:rules/Rules1.drl"/>
<drools-spring:resource source="classpath:rules/Rules3.drl"/>
</drools-spring:resources>
</drools-spring:kbase>
<drools-spring:kbase id="rules2And3">
<drools-spring:resources>
<drools-spring:resource source="classpath:rules/Rules2.drl"/>
<drools-spring:resource source="classpath:rules/Rules3.drl"/>
</drools-spring:resources>
</drools-spring:kbase>
<bean id="ruleSessionAutoRefundAndPox" factory-bean="rules1And3"
factory-method="newStatelessKnowledgeSession"/>
<bean id="ruleSessionNonCashRefund" factory-bean="rules2And3"
factory-method="newStatelessKnowledgeSession"/>
</beans>
所以这里有 3 个规则下的文件。第一个 kbase 只有规则 1 和规则 2,第二个 kbase 只有规则 2 和规则 3。
它在 7.x 中“应该”是什么样子:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:kie="http://drools.org/schema/kie-spring"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">
<kie:kmodule id="rules">
<kie:kbase name="rules1And3">
<!--loaded drl files-->
</kie:kbase>
<kie:kbase name="rules2And3">
<!--loaded drl files-->
</kie:kbase>
</kie:kmodule>
<!-- maybe these are unnecessary and instead ksessions should been defined within kbase elements-->
<bean id="sessionRules1And3" factory-bean="rules1And3"
factory-method="newStatelessKnowledgeSession"/>
<bean id="sessionRules2And3" factory-bean="rules2And3"
factory-method="newStatelessKnowledgeSession"/>
</beans>
根据我所看到的,我什至不确定在新版本中是否可以实现相同的行为,或者整个方法可能是错误的,但我想要的是能够定义为基数。
感谢您的帮助!
【问题讨论】: