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();
     }
}
As hinted in the comments, it's a Drools compilation issue! In the logs, I get:
KieProject - Unable to build KieBaseModel:defaultKieBase
[3,14]: [ERR 107] Line 3:14 mismatched input 'java' expecting one of the following tokens: '[package, unit, import, global, declare, function, rule, query]'.
This message doesn’t direct you to the exact error but the general region. I checked the import section, and I had put import in one cell, and then in the list of packages to import, I had put the "import" keyword again. I corrected it to match the examples online, and the spreadsheet compiles!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With