安装程序使用spring 4降低6时出错-类型规则\u续订\u警报\u的方法processData(LicenseCredential)未定义[u 60]
我不太会流口水。我用spring-4.1和drool-6.1.0.Final设置了一个新项目。但当我尝试运行project时,我会出现以下错误安装程序使用spring 4降低6时出错-类型规则\u续订\u警报\u的方法processData(LicenseCredential)未定义[u 60],spring,java-8,drools,kie,Spring,Java 8,Drools,Kie,我不太会流口水。我用spring-4.1和drool-6.1.0.Final设置了一个新项目。但当我尝试运行project时,我会出现以下错误 Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoalert-ksession-stateless': Cannot resolve reference to bean
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoalert-ksession-stateless': Cannot resolve reference to bean 'autoalert-kbase' while setting bean property 'kBase'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoalert-kbase': Invocation of init method failed; nested exception is java.lang.RuntimeException: Error while creating KieBase[Message [id=1, level=ERROR, path=drools/rules/Rule.drl, line=27, column=0
text=[ function processDataprocessData (line:27): learnerCsvFileWriter cannot be resolved
]], Message [id=2, level=ERROR, path=drools/rules/Rule.drl, line=33, column=0
text=Rule Compilation error The import defaultpkg.ProcessData cannot be resolved
The method processData(LicenseCredential) is undefined for the type Rule_Renewal_alert_for_60_days2039807096], Message [id=3, level=ERROR, path=drools/rules/Rule.drl, line=-1, column=0
text=Error importing : 'defaultpkg.ProcessData.processData']]
这是我的spring和drools配置文件
drools-context.xml
<kie:kmodule id="autoalert-module">
<kie:kbase name="autoalert-kbase" packages="drools.rules">
<kie:ksession name="autoalert-ksession-stateless" type="stateless" />
</kie:kbase>
</kie:kmodule>
<bean id="kiePostProcessor" class="org.kie.spring.KModuleBeanFactoryPostProcessor"/>
<context:annotation-config />
<context:property-placeholder location="classpath:autoalert.properties" ignore-unresolvable="true" />
<import resource="classpath:database/datasource-tx.xml" />
<import resource="classpath:drools/drools-context.xml" />
<bean id="csvFileWriter" class="com.softech.vu360.autoalert.CsvFileWriter" />
<bean id="businessRuleProcessor" class="com.softech.vu360.autoalert.rule.BusinessRuleProcessor">
<property name="statelessKieSession" ref="autoalert-ksession-stateless" />
<property name="csvFileWriter" ref="csvFileWriter" />
</bean>
这是我的POM文件:
<properties>
<java-version>1.8</java-version>
<junit.version>4.12</junit.version>
<!-- Spring -->
<org.springframework.version>4.1.4.RELEASE</org.springframework.version>
<!-- Drools -->
<drools.version>6.1.0.Final</drools.version>
<drools-maven-plugin.version>6.0.0.CR5</drools-maven-plugin.version>
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
...
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
....
<!-- Drools -->
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-spring</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.jbpm</groupId>
<artifactId>jbpm-bpmn2</artifactId>
<version>${drools.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Maven compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
....
<plugin>
<groupId>org.drools</groupId>
<artifactId>drools-maven-plugin</artifactId>
<version>${drools-maven-plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
请帮忙
谢谢奇怪的是,函数processDataprocessData中指示了一个错误,这不在您发布的DRL中,但另一个错误表示DRL中没有函数processData。你伪造密码了吗 但问题很简单,您不能在函数中引用全局变量。要使用全局变量,请将其作为参数传递
function void processData(LicenseCredential licenseCredential,
CsvFileWriter learnerCsvFileWriter ){
....
}
rule ...
then
System.out.println("Rule For 60 Days Called");
processData(licenseCredential, learnerCsvFileWriter);
end
请将所有投诉提交给Drools团队 我觉得这可能与包定义的问题有关。看起来您并没有为您的规则设置包名(因此
defaultpkg
),而是将其放入包中drools/rules/
。您的意思是说我需要在规则文件中定义包声明。像包drools.rules代码>在我的drl文件中?这是一个起点。Drools查找在src/main/resources
下的包中定义的规则,遵循Java风格的包结构。就像Java类一样,如果规则位于drools/rules
目录中,那么它应该将其包声明为drools.rules
代码>,但现在错误消息仅更改为规则编译错误导入drools.rules.ProcessData无法解析
,因此您的规则文件现在是:src/main/resources/drools/rules/ProcessData.drl
?啊。。。谢谢你,伙计。这是有效的。非常感谢你。我认为通过定义全局变量,您可以在任何地方使用它,而无需将其传递给函数。无论如何,再次谢谢你。但我什么也没做。我不知道为什么它会在日志中显示processDataprocessData,
。正如我说的,我是个流口水的新手。但是所有的错误都消失了,现在它工作得很好。谢谢你和史蒂夫;):)
public static void main(String[] args){
final ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
LicenseCredentialDAO dao = (LicenseCredentialDAOImpl)context.getBean("licenseCredentialDAO");
List<LicenseCredential> objectList = dao.select();
BusinessRuleProcessor ruleProcessor = (BusinessRuleProcessor)context.getBean("businessRuleProcessor");
ruleProcessor.configureAndApplyRulesOnObject(objectList);
CsvFileWriter learnerCsvFileWriter = context.getBean("csvFileWriter", CsvFileWriter.class);
learnerCsvFileWriter.writeCsvFile("abc.csv");
}
public class BusinessRuleProcessor {
private StatelessKieSession statelessKieSession;
private CsvFileWriter csvFileWriter;
// getters and setters
public void configureAndApplyRulesOnObject(List<LicenseCredential> objectList){
statelessKieSession.setGlobal("learnerCsvFileWriter", csvFileWriter);
statelessKieSession.execute(objectList);
}
}
function processDataprocessData (line:27): learnerCsvFileWriter cannot be resolved
Rule Compilation error The import defaultpkg.ProcessData cannot be resolved
The method processData(LicenseCredential) is undefined for the type Rule_Renewal_alert_for_60_days2039807096]
function void processData(LicenseCredential licenseCredential,
CsvFileWriter learnerCsvFileWriter ){
....
}
rule ...
then
System.out.println("Rule For 60 Days Called");
processData(licenseCredential, learnerCsvFileWriter);
end