drools6集成spring
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了drools6集成spring相关的知识,希望对你有一定的参考价值。
参考文章链接
http://justsee.iteye.com/blog/1279082
http://liureying.blog.163.com/blog/static/6151352011111810916588/
http://blog.csdn.net/sinat_24910337/article/details/50587793
https://hub.docker.com/r/jboss/drools-workbench/
http://my.oschina.net/CandyDesire/blog/342055
http://shikonglaike.iteye.com/blog/1236354
1、在drools官网下载Drools Engine(jar文件、源码、文档、示例)、Drools Workbench、Drools and jBPM tools(Eclipse plugins and support for Drools),官网链接:http://www.drools.org/download/download.html
下载链接:
http://download.jboss.org/drools/release/6.4.0.Final/drools-distribution-6.4.0.Final.zip
http://download.jboss.org/drools/release/6.4.0.Final/kie-drools-wb-distribution-wars-6.4.0.Final-tomcat7.war
http://download.jboss.org/drools/release/6.4.0.Final/droolsjbpm-tools-distribution-6.4.0.Final.zip
2、给Eclipse安装Drools插件,用于编辑drl文件、创建drools工程等。
将droolsjbpm-tools-distribution-6.4.0.Final.zip文件中的
droolsjbpm-tools-distribution-6.4.0.Final.zip
droolsjbpm-tools-distribution-6.4.0.Final
binaries
org.drools.updatesite
文件夹解压出来,重新打成一个zip文件
打开MyEclipse,在Help下选择Install from site...
在弹出的对话框中选择Add添加本地zip文件
不要勾选红框中的插件,点击下一步,下一步,同意协议后开始安装,完成后重新启动MyEclipse。
3、新建一个空白drools工程
新建的工程结构如下
其中的pom.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>drools.group</groupId> <artifactId>drools.artifact</artifactId> <version>1.0</version> </project>
pom.properties文件内容如下:
1 groupId=drools.group 2 artifactId=drools.artifact 3 version=1.0
kmodule.xml文件内容如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"> 3 <kbase name="rules" packages="rules"> 4 <ksession name="ksession-rules"/> 5 </kbase> 6 <kbase name="dtables" packages="dtables"> 7 <ksession name="ksession-dtables"/> 8 </kbase> 9 <kbase name="process" packages="process"> 10 <ksession name="ksession-process"/> 11 </kbase> 12 </kmodule>
4、在pom.xml文件添加如下依赖
<drools.version>6.4.0.Final</drools.version>
1 <!-- drools规则引擎 begin --> 2 <dependency> 3 <groupId>org.drools</groupId> 4 <artifactId>drools-core</artifactId> 5 <version>${drools.version}</version> 6 </dependency> 7 <dependency> 8 <groupId>org.drools</groupId> 9 <artifactId>drools-decisiontables</artifactId> 10 <version>${drools.version}</version> 11 </dependency> 12 <dependency> 13 <groupId>org.drools</groupId> 14 <artifactId>drools-templates</artifactId> 15 <version>${drools.version}</version> 16 </dependency> 17 <dependency> 18 <groupId>org.drools</groupId> 19 <artifactId>drools-compiler</artifactId> 20 <version>${drools.version}</version> 21 </dependency> 22 <dependency> 23 <groupId>org.drools</groupId> 24 <artifactId>knowledge-api</artifactId> 25 <version>${drools.version}</version> 26 </dependency> 27 <dependency> 28 <groupId>org.kie</groupId> 29 <artifactId>kie-spring</artifactId> 30 <version>${drools.version}</version> 31 </dependency> 32 <dependency> 33 <groupId>org.kie</groupId> 34 <artifactId>kie-api</artifactId> 35 <version>${drools.version}</version> 36 </dependency> 37 <dependency> 38 <groupId>org.kie</groupId> 39 <artifactId>kie-ci</artifactId> 40 <version>${drools.version}</version> 41 </dependency> 42 <dependency> 43 <groupId>org.kie</groupId> 44 <artifactId>kie-internal</artifactId> 45 <version>${drools.version}</version> 46 </dependency> 47 <dependency> 48 <groupId>org.mvel</groupId> 49 <artifactId>mvel2</artifactId> 50 <version>2.2.8.Final</version> 51 </dependency> 52 <dependency> 53 <groupId>com.google.protobuf</groupId> 54 <artifactId>protobuf-java</artifactId> 55 <version>2.6.0</version> 56 </dependency> 57 <dependency> 58 <groupId>org.antlr</groupId> 59 <artifactId>antlr-runtime</artifactId> 60 <version>3.5</version> 61 </dependency> 62 <dependency> 63 <groupId>antlr</groupId> 64 <artifactId>antlr</artifactId> 65 <version>2.7.2</version> 66 </dependency> 67 <dependency> 68 <groupId>com.thoughtworks.xstream</groupId> 69 <artifactId>xstream</artifactId> 70 <version>1.4.7</version> 71 </dependency> 72 <!-- drools规则引擎 end -->
新建spring-drools.xml文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:kie="http://drools.org/schema/kie-spring" 4 xmlns:camel="http://camel.apache.org/schema/spring" 5 xsi:schemaLocation=" 6 http://drools.org/schema/kie-spring https://raw.githubusercontent.com/droolsjbpm/droolsjbpm-integration/master/kie-spring/src/main/resources/org/kie/spring/kie-spring-6.0.0.xsd 7 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 8 http://drools.org/schema/kie-spring http://drools.org/schema/kie-spring.xs"> 9 <!-- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd --> 10 <!-- 每5分钟扫描是否有新版本文件 --> 11 <kie:import releaseId-ref="ksession-releaseId" 12 enableScanner="true" scannerInterval="300000" /> 13 <kie:releaseId id="ksession-releaseId" groupId="com.demo" 14 artifactId="risk" version="REALEASE" /> 15 <bean id="kiePostProcessor" class="org.kie.spring.annotations.KModuleAnnotationPostProcessor" /> 16 <!-- -Dspring.profiles.active="development" --> 17 <beans profile="development"> 18 <kie:kmodule id="test-kmodule"> 19 <kie:kbase name="drl_kiesample" packages="drl_kiesample"> 20 <kie:ksession name="ksession1" type="stateful"> 21 <kie:consoleLogger /> 22 <kie:batch> 23 <kie:insert-object ref="person2" /> 24 <kie:set-global identifier="persons" ref="personsList" /> 25 <kie:fire-all-rules max="10" /> 26 </kie:batch> 27 </kie:ksession> 28 </kie:kbase> 29 </kie:kmodule> 30 </beans> 31 </beans>
以上是关于drools6集成spring的主要内容,如果未能解决你的问题,请参考以下文章