java – 版本6.2的drools代码不推荐使用
作者:互联网
我有一个旧的和已删除的drools代码,这段代码可以读取容器外的规则文件(drl),并且可以使用任何Value Object和任何类.
CommandExecutor ksession;
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
String file = System.getenv("DOMAIN_HOME")+"/mydrls/business.drl";
kbuilder.add(ResourceFactory.newFileResource(file), ResourceType.DRL);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
ksession = kbase.newStatelessKnowledgeSession();
DataTest data = new DataTest();
data.setAge(25);
List cmds = new ArrayList();
cmds.add( CommandFactory.newInsert( data ) );
ksession.execute(CommandFactory.newBatchExecution( cmds ));
我怎么能用drools版本6.2做同样的事情?
解决方法:
您可以使用KieHelper类简化Laune的代码:
KieHelper kieHelper = new KieHelper();
kieHelper.addResource(ResourceFactory.newInputStreamResource(new FileInputStream( "simple/simple.drl" )), ResourceType.DRL);
Results results = kieHelper.verify();
if( results.hasMessages( Message.Level.ERROR ) ){
System.out.println( results.getMessages() );
throw new IllegalStateException( "### errors ###" );
}
StatelessKieSession kieSession = kieHelper.build().newStatelessKieSession();
希望能帮助到你.
标签:drools,java,rule-engine 来源: https://codeday.me/bug/20191002/1842823.html