一.<beans>加入drools的命名空间
http://drools.org/schema/drools-spring http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd
二.增加jar包库
drools-spring jar
三.spring 配置文件声明KnowledgeBase 配置文件
<drools:kbase id=”kBase”>
<drools:resources>
<!–drools:resource type=”规则文件类型” source=”规则文件” –>
<drools:resource type=”DRL” source=”classpath:com/demo/insert.drl” />
</drools:resources>
<!– drools:configuration> <drools:mbeans enabled=”true” /> <drools:event-processing-mode
mode=”STREAM” /> </drools:configuration –>
</drools:kbase>
四.声明与规则引擎进行交互session.配置
StatelessKnowledgeSession在spring内配置
<drools:ksession id=”ksession1″ type=”stateless” name=”stateless1″ kbase=”kBase” />
StatefulKnowledgeSession在spring内配置
<drools:ksession id=”session” type=”stateful” kbase=”kBase” />
五.程序代码实例测试
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { “com/demo/spring/mydrools.xml” });
StatefulKnowledgeSession session = (StatefulKnowledgeSession) context
.getBean(“session”);
session.fireAllRules();
session.dispose();
System.out.println(“end”);
转载请注明来源网站:blog.ytso.com谢谢!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/14628.html