我正在使用Drools 5.4 我有时会遇到错误 引起:org.mvel2.CompileException:[错误:无法使用strict-mode解析方法:com.model.SPurpose.APurpose()] [近:{...目的== APurpose.S_ELIG ....}]
here is my classes
package com.model
public class SPurpose {
private APurpose purpose;
public SPurpose(APurpose purpose){
this.setPurpose(purpose);
}
public APurpose getPurpose() {
return purpose;
}
public void setPurpose(APurpose purpose) {
this.purpose = purpose;
}
}
package com.setup.model
public enum APurpose {
P_ELIG,
S_ELIG,
E_CALC,
S_VEST;
public String value() {
return name();
}
public static APurpose fromValue(String v) {
return valueOf(v);
}
}
I am using the DRL file
file name is service.drl
rule "calculate Elig"
when
SPurpose(purpose == APurpose.S_ELIG)
SMethod(sMethod == sMethod.HCOUNTING)
then
insert(new Hours());
end;
import java.util.Date;
import java.util.List;
import org.drools.KnowledgeBase;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.rule.Row;
import org.drools.runtime.rule.ViewChangedEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.model.SPurpose;
import com.setup.model.APurpose;
class ServiceImpl implements Service {
private static final Logger logger = LoggerFactory
.getLogger(ServiceImpl.class);
ServiceCalculationServiceImpl(
final KnowledgeBase kbase) {
this.kbase = kbase;
}
private static final Resource[] resources = {
new ClassPathResource("com/rules/service.drl"),
new ClassPathResource("com/rules/break.drl")};
public void calculateService(final Input input,
final Output output) throws ServiceCalculationException {
{
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (Resource resource : resources) {`enter code here`
kbuilder.add(resource, ResourceType.DRL);
if (kbuilder.hasErrors()) {
String s = kbuilder.getErrors().toString();
throw new IllegalStateException(s);
}
}
kbase = kbuilder.newKnowledgeBase();
StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
ksession.insert(input);
ksession.insert(new SMethod(input.getSMethod()));
ksession.insert(new SPurpose(input.getPurpose()));// Adding the purpose
ksession.insert(output);
ksession.fireAllRules();
ksession.dispose();
}
}
any advice on it