Home > OS >  RuleUnitProvider.get() throws an error when called from a Spring Boot RequestController
RuleUnitProvider.get() throws an error when called from a Spring Boot RequestController

Time:02-03

I have a spring-boot project that uses

        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-ruleunits-engine</artifactId>
            <version>8.33.0.Final</version>
        </dependency>

I have rules set up using a RuleUnit and everything works correctly when running basic Unit Tests. In my Unit Tests I use this line: RuleUnitProvider.get().createRuleUnitInstance(requestAccessUnit); to create a RuleUnitInstance and it works w/o issue.

However, when I try to instantiate the same RuleUnitInstance in my @RequestController I get the following error:

java.lang.RuntimeException: Cannot find any rule unit for RuleUnitData of class:yyyy.xxxx.zzzz.RuleUnit

The previous log statement shows KieProject - No files found for KieBase defaultKieBase which leads me to believe that it's not able to load the rule files into the KieBase.

Do I have to use the kie-maven-plugin and change my package to kjar in order for this to work? Is there a way to get this to work w/o using the kjar packaging? The way our build is set up makes it very problematic to use kjar.

I didn't see a lot in the documentation regarding using RuleUnits in Spring Boot so I am not sure how to proceed. I tried doing this in Kogito as well and ran into the same issue.

CodePudding user response:

For best integration of Drools with Spring Boot and per your StackOverflow question tags, you should consider using Kogito --and therefore using the Kogito API or Kogito Incubation API (rather than just directly the Drools API).

  • Related