我正在使用 Gradle 和 7.20 drools 版本创建一个 spring boot 应用程序。我们正在从位于路径的外部资源文件中加载 drools 知识库。drl_file_path
下面是我的配置代码。
@Configuration
public class DroolConfig {
KieServices kieServices = KieServices.Factory.get();
@Bean
public KieFileSystem kieFileSystem() throws IOException {
KieFileSystem kieFileSystem =kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newFileResource(new File("drl_file_path")));
return kieFileSystem;
}
@Bean
public KieContainer kieContainer() throws IOException{
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem());
kieBuilder.buildAll();
KieModule kieModule = kieBuilder.getKieModule();
KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
KieScanner kScanner = kieServices.newKieScanner(kieContainer);
kScanner.start( 10000L );
return kieContainer;
}
@Bean
public KieScanner kieScanner() throws IOException{
return kieServices.newKieScanner(kieContainer());
}
}
有机会我们必须更新drools规则,我们想在不重新启动服务器的情况下更新drools知识库,我们正在使用KieScanner.sacnNow()
哪个不起作用,我缺少什么关键点。下面是重新加载和应用drools规则的代码-
@Component
public class DroolComponent {
@Autowired private KieContainer kieContainer;
@Autowired private KieScanner kieScanner;
public Customer reloadDroolsAndApply(Customer customer) {
kieScanner.scanNow();
//above scanning not applying updated rules.
KieSession kieSession = kieContainer.newKieSession();
kieSession.insert(customer);
kieSession.fireAllRules();
kieSession.dispose();
return customer;
}
}