配置drools和maven并使用它们编写hello world应用程序

Anu*_*pta 7 java drools maven

我想学习drools和maven任何人都可以帮助我配置drools和maven的链接,并使用它们编写一个基本的hello world示例.

提前致谢

Joh*_*nak 11

您应该首先阅读手册,然后尝试谷歌.之前也有过这样的问题,例如:如何通过我的Web应用程序部署Drools Flow和规则

但无论如何.如果您使用Maven和Spring,这是如何集成它:

首先需要包含Drools依赖项:

    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-core</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
        <version>${drools.version}</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-spring</artifactId>
        <version>${drools.version}</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

定义应用程序上下文:

<?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:drools="http://drools.org/schema/drools-spring"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
            http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd">


    <drools:kbase id="kbase1">
        <drools:resources>
            <drools:resource source="classpath:Sample.drl" />
        </drools:resources>
    </drools:kbase>

    <drools:ksession id="ksession1" type="stateful" kbase="kbase1" />

</beans>
Run Code Online (Sandbox Code Playgroud)

然后你可以注入ksession1bean.