Migrating Spring drools-context.xml from 5.0 to 6.

2020-05-06 00:54发布

问题:

In drools 6, there have been some changes to the Spring integration, such that the resources are no longer specified.

    <drools:resources>
        <drools:resource type="DRL"
                         source="classpath:rules/products.drl"/>
    </drools:resources>

How do I specify them in version 6, then?

回答1:

Note that in Drools 6, drl files to be loaded should be placed under main/resources folder in your maven project. During runtime say in Tomcat, drl files will appear under <yourwebapp>/WEB-INF/classes folder.

Sample xml config:

<?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/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xsd">

<kie:kmodule id="kmoduleCEP">
    <kie:kbase name="kbaseCEP" eventProcessingMode="stream"
        equalsBehavior="equality">
        <kie:ksession name="ksessionCEP" type="stateful"
            clockType="realtime">
            <kie:agendaEventListener ref="agendaEventListener" />
            <kie:ruleRuntimeEventListener ref="workingMemoryEventListener" />
            <kie:batch>
                <kie:set-global identifier="callbackService">
                    <ref bean="callbackService" />
                </kie:set-global>
            </kie:batch>
        </kie:ksession>
    </kie:kbase>
</kie:kmodule>

</beans>

Instead of drools-spring artifact use kie-spring. something like:

<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-spring</artifactId>
    <version>${org.drools.version}</version>
</dependency>
<dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-api</artifactId>
    <version>${org.drools.version}</version>
</dependency>                       
<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-core</artifactId>
    <version>${org.drools.version}</version>
</dependency>