Drools+Eclipse+Spring

   結合DroolsEclipse

 

1)  準備工作:到網站下載http://jboss.org/drools/downloads.html Drools相關的插件包Drools and jBPM tools(以下版本是5.3.0),並解壓。

2)  進行集成:打開Eclipse選擇Help下面的Install New Software

    選擇Add並選擇Local並找到解壓後binaries文件下面的org.drools.updatesite,然後進行安裝,安裝完成重啓即可。(詳情可參考文件夾解壓後的ReadMeDroolsJbpmTools.txt文件)

 

結合DroolsSpring

 

我們知道每次如果插入一個事件,都需要獲得StatefulKnowledgeSession或者StatelessKnowledgeSession對象,而獲得這個對象都需要初始化很多對象。此時很多人想到用Singleton方式,但是我們還想Session的狀態也讓Drools 給我們管理,這是我們想到了強大的Spring,我們可以使用Spring基本的DI功能,我們想要獲得Session時,只需要在Spring容器找就可以了。

 

1)       準備工作:還是剛纔那個網站,下載Drools and jBPM integration包。我們需要裏面的Spring包以及drools-grid-impl-5.3.0.Final.jardrools-spring-5.3.0.Final.jar

2)       建立spring配置文件beans-drools.xml

<?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="http://drools.org/schema/drools-spring"
	xmlns:camel="http://camel.apache.org/schema/spring"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                           http://drools.org/schema/drools-spring http://drools.org/schema/drools-spring.xsd
                           http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
	<drools:kbase id="kbase1">
		<drools:resources>
			<drools:resource type="DRL"
				source="classpath:pku/test/rules/FirstRule.drl" />
		</drools:resources>
	</drools:kbase>

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

	<!-- <bean id="vip" class="com.jsptpd.rjy.zyj.pojo.Vip" /> -->
	<bean id="ruleService" class="pku.test.service.RuleServiceByDrools">
		<property name="session" ref="ksession1" />
	</bean>
</beans>

 

Spring的基本配置文件beans.xml中引用beans-drools.xml:

 

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

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章