Home > Software engineering >  Spring boot drools integration not woking after drools updated from version 7.73.0.Final to 8.29.0.F
Spring boot drools integration not woking after drools updated from version 7.73.0.Final to 8.29.0.F

Time:11-02

We were using spring boot drools maven dependency drl files for implementing certain business rules in our spring boot application.We used the following drools dependencies(drools-core, drools-compiler, drools-decisiontables) with the version 7.73.0.The integration is not woking after drools updated from version 7.73.0.Final to 8.29.0.Final.Please find the implementation and error trace below.Can someone help to resolve the same

My Config Class

@Configuration
public class DroolsConfig {

    private static final String RULES_DRL = "rules/rule-impl.drl";
    private static final KieServices kieServices = KieServices.Factory.get();

    @Bean
    public KieContainer kieContainer() {
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_DRL));
        KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
        kb.buildAll();
        KieModule kieModule = kb.getKieModule();
        return kieServices.newKieContainer(kieModule.getReleaseId());
    }

}

Calling class

 @Autowired
    private KieContainer kieContainer;

    public String applyCleansingRules(String name) {
         /////////
        KieSession kieSession = kieContainer.newKieSession();
        /////
        kieSession.insert(name);
        kieSession.fireAllRules(1);
        kieSession.dispose();
        return /////
    }

Error Message :

at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar:2.7.0]
    at com.rule.engine.RuleEngineApplication.main(RuleEngineApplication.java:10) ~[classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kieContainer' defined in class path resource [com/rule/engine/config/DroolsConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 20 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.NullPointerException
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.20.jar:5.3.20]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.20.jar:5.3.20]
    ... 33 common frames omitted
Caused by: java.lang.NullPointerException: null
    at org.drools.compiler.rule.builder.PatternBuilder.buildAnalysis(PatternBuilder.java:1597) ~[drools-compiler-8.29.0.Final.jar:8.29.0.Final]
    at org.drools.compiler.rule.builder.PatternBuilder.buildEval(PatternBuilder.java:1499) ~[drools-compiler-8.29.0.Final.jar:8.29.0.Final]

Trace Junit Test :

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '******Service': Unsatisfied dependency expressed through field 'kieContainer'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kieContainer' defined in class path resource [com/rule/engine/config/DroolsConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.NullPointerException
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kieContainer' defined in class path resource [com/rule/engine/config/DroolsConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.NullPointerException
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception; nested exception is java.lang.NullPointerException
Caused by: java.lang.NullPointerException

CodePudding user response:

Hard to tell. It seems that one of your rules is using something inside an eval() that is no longer supported in 8.29.0.

You will need to start removing DRLs from your KieBase or commenting out rules containing eval() until you find the problematic one.

From the code, it could also be related to the dialect you are using. Are you specifying an explicit dialect for your rules?

CodePudding user response:

This is not a solution to your immediate problem but with the information I've seen in your problem statement, you should in theory be able to move "seamlessly" between drools 7 -> 8.29.0.Final. However, I've seen the same result of it giving you issues with kieContainer. I'm not sure if this was "fully" tested for backward compatibility.

Having said that, the new version where RuleUnitData is being used does work very well but will take some rework: https://docs.drools.org/8.29.0.Final/drools-docs/docs-website/drools/migration-guide/index.html#con-migration-to-kogito-overview_migration-guide

Cheers, Chris

  • Related