DEV Community

Cover image for Drools integration with Spring Boot

Drools integration with Spring Boot

raja_anbazhagan profile image Raja Anbazhagan Originally published at ・1 min read

Drools is a versatile business rule engine that can elevate your application by externalizing a lot of decision logic. As the most application servers are now using Spring boot, let's understand how to use Drools with Spring boot.

For a simple example, you can create a KieContainer as shown below.

public KieContainer getKieContainer() {
    KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
    kieFileSystem.write( ResourceFactory.newClassPathResource("discount.drl"));
    KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
    KieModule kieModule = kb.getKieModule();
    return kieServices.newKieContainer(kieModule.getReleaseId());
Enter fullscreen mode Exit fullscreen mode

Once you have a container, You can execute the rules within it by creating a session and firing all rules.

More on this explained at Drools integration with Spring Boot.

Discussion (0)

Editor guide