尝试创建新会话时出现空指针异常:
使用AWS Lambda(java .jar文件)+ Drools规则引擎的java.lang.NullPointerException kContainer.newKieSessiona。]
public class LambdaRequestHandler implements RequestHandler<String, String> {
@Override
public String handleRequest(String input, Context context) {
context.getLogger().log("Input: " + input);
int rulesFired = 0;
try {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");
Account account = new Account(200);
account.withdraw(150);
kSession.insert(account);
rulesFired = kSession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
return "Rules Fired - " + rulesFired;
}
}
Rules.drl file
package rules
import Account
rule "accountBalanceCheck1"
when
$account : Account( balance < 100 )
then
System.out.println("Inside rule 1");
end
kmodule.xml file
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="rules" packages="rules">
<ksession name="ksession-rules"/>
</kbase>
<kbase name="rules2" packages="rules">
<ksession name="statelessSession" type="stateless" default="true"/>
</kbase>
<kbase name="dtables" packages="dtables">
<ksession name="ksession-dtables"/>
</kbase>
<kbase name="process" packages="process">
<ksession name="ksession-process"/>
</kbase>
</kmodule>
任何帮助将不胜感激!