I'm using the following drools configuration file in a Spring Boot application to load/execute rules from a DataBase which runs fine locally but when I try deploying the application to a Server i got an error saying no KieModule Bean found. I added the missing KieModule Bean to my config file and now i'm getting another error Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.RuntimeException: Cannot find KieModule: org.default:artifact:1.0.0-SNAPSHOT
. My question is 1) why do i need this Bean and 2) why does the application build/run locally without the missing Bean?
If its a mandatory Bean required for deploying the application, do i need to config it specifically for my environment by adding some properties to my application/POM??
public class DroolsDataBaseConfig {
@Autowired
private DataService dataService;
@PostConstruct
public void loadResourcesFromDatabase() {
try {
KieHelper helper = getKieHelper();
List<Rule> rulesFromDB = dataService.findAllRules();
for (Rule rule : rulesFromDB){
String ruleAsStr = rule.getRule();
helper.addContent(ruleAsStr, ResourceType.DRL);
}
helper.build(getKieServices().newKieBaseConfiguration());
} catch (Exception ex) {
log.error("Exception occured loading rules from Database. Exception is : " + ex);
}
}
@Bean
@ConditionalOnMissingBean(KieContainer.class)
public KieContainer kieContainer() throws IOException {
final KieRepository kieRepository = getKieServices().getRepository();
return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());
}
@Bean
@ConditionalOnMissingBean(StatelessKieSession.class)
public StatelessKieSession statelessKieSession() throws IOException {
return kieContainer().newStatelessKieSession();
}
private KieServices getKieServices() {
return KieServices.Factory.get();
}
@Bean
@ConditionalOnMissingBean(KieHelper.class)
public KieHelper getKieHelper() throws IOException {
return new KieHelper();
}
@Bean
@ConditionalOnMissingBean(KieModule.class)
public KieModule kieModule() throws IOException {
return new KieModule() {
public ReleaseId getReleaseId() {
return getKieServices().getRepository().getDefaultReleaseId();
}
};
}
@Bean
@ConditionalOnMissingBean(KieBase.class)
public KieBase kieBase() throws IOException {
return kieContainer().getKieBase();
}
}