{"id":3778,"date":"2025-12-24T10:00:11","date_gmt":"2025-12-24T15:00:11","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3778"},"modified":"2025-12-24T10:00:11","modified_gmt":"2025-12-24T15:00:11","slug":"integrating-drools-with-a-spring-boot-microservice","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-drools-with-a-spring-boot-microservice\/","title":{"rendered":"Integrating Drools with a Spring Boot Microservice"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><p>This blog post will guide you through integrating the Drools rule engine with your Spring Boot microservice. We\u2019ll cover the necessary dependencies, configuration, and an example service to demonstrate its usage.<\/p>\n<p><strong>1. Project Setup and Dependencies<\/strong><\/p>\n<p>Start by creating a Spring Boot project using Spring Initializr or your preferred IDE.  Next, add the following Drools dependencies to your <code>pom.xml<\/code> (Maven) or <code>build.gradle<\/code> (Gradle) file:<\/p>\n<p><strong>Maven:<\/strong><\/p>\n<pre><code class=\"language-xml\">&lt;dependency&gt;\n    &lt;groupId&gt;org.kie&lt;\/groupId&gt;\n    &lt;artifactId&gt;kie-spring&lt;\/artifactId&gt;\n    &lt;version&gt;7.71.0.Final&lt;\/version&gt; \n&lt;\/dependency&gt;\n<\/code><\/pre>\n<p><strong>Gradle:<\/strong><\/p>\n<pre><code class=\"language-gradle\">implementation 'org.kie:kie-spring:7.71.0.Final'\n<\/code><\/pre>\n<p><strong>2. Drools Configuration<\/strong><\/p>\n<p>Create a configuration class to set up the Drools environment. This class will define beans for <code>KieFileSystem<\/code>, <code>KieContainer<\/code>, <code>KieSession<\/code>, and optionally a <code>KieBase<\/code>.<\/p>\n<pre><code class=\"language-java\">import org.kie.api.KieServices;\nimport org.kie.api.builder.KieBuilder;\nimport org.kie.api.builder.KieFileSystem;\nimport org.kie.api.builder.KieModule;\nimport org.kie.api.builder.KieRepository;\nimport org.kie.api.runtime.KieContainer;\nimport org.kie.api.runtime.KieSession;\nimport org.kie.internal.io.ResourceFactory;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.core.io.Resource;\nimport org.springframework.core.io.support.PathMatchingResourcePatternResolver;\nimport org.springframework.core.io.support.ResourcePatternResolver;\n\nimport java.io.IOException;\n\n@Configuration\npublic class DroolsConfig {\n\n    private static final String RULES_PATH = &quot;rules\/&quot;;\n\n    @Bean\n    public KieFileSystem kieFileSystem() throws IOException {\n        KieFileSystem kieFileSystem = getKieServices().newKieFileSystem();\n        for (Resource file : getRuleFiles()) {\n            kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + file.getFilename(), &quot;UTF-8&quot;));\n        }\n        return kieFileSystem;\n    }\n\n    private Resource[] getRuleFiles() throws IOException {\n        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();\n        return resourcePatternResolver.getResources(&quot;classpath*:&quot; + RULES_PATH + &quot;**\/*.*&quot;);\n    }\n\n    @Bean\n    public KieContainer kieContainer() throws IOException {\n        final KieRepository kieRepository = getKieServices().getRepository();\n        kieRepository.addKieModule(new KieModule() {\n            public ReleaseId getReleaseId() {\n                return kieRepository.getDefaultReleaseId();\n            }\n        });\n\n        KieBuilder kieBuilder = getKieServices().newKieBuilder(kieFileSystem());\n        kieBuilder.buildAll();\n        return getKieServices().newKieContainer(kieRepository.getDefaultReleaseId());\n    }\n\n    private KieServices getKieServices() {\n        return KieServices.Factory.get();\n    }\n\n    @Bean\n    public KieSession kieSession() throws IOException {\n        return kieContainer().newKieSession();\n    }\n\n}\n<\/code><\/pre>\n<p>This configuration:<\/p>\n<ul>\n<li>Defines the <code>RULES_PATH<\/code> where your Drools rule files (<code>.drl<\/code>) will be located.<\/li>\n<li>Creates a <code>KieFileSystem<\/code> and loads all rule files from the specified path.<\/li>\n<li>Builds a <code>KieContainer<\/code> to hold the compiled rules.<\/li>\n<li>Creates a <code>KieSession<\/code> which is the primary interface for interacting with the Drools engine.<\/li>\n<\/ul>\n<p><strong>3.  Create Drools Rule Files<\/strong><\/p>\n<p>Create a <code>rules<\/code> directory in your <code>src\/main\/resources<\/code> folder. Add your Drools rule files (<code>.drl<\/code> files) here. For example, <code>discount.drl<\/code>:<\/p>\n<pre><code class=\"language-drools\">rule &quot;Apply 10% discount for orders over $100&quot;\nwhen\n    order : Order(totalPrice &gt; 100)\nthen\n    order.applyDiscount(0.1); \nend\n<\/code><\/pre>\n<p><strong>4. Using the Drools Engine in a Service<\/strong><\/p>\n<p>Inject the <code>KieSession<\/code> bean into your service class and use it to fire rules against your domain objects.<\/p>\n<pre><code class=\"language-java\">import org.kie.api.runtime.KieSession;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\n@Service\npublic class OrderService {\n\n    @Autowired\n    private KieSession kieSession;\n\n    public Order applyRules(Order order) {\n        kieSession.insert(order);\n        kieSession.fireAllRules();\n        return order;\n    }\n}\n<\/code><\/pre>\n<p><strong>5. YML Configuration (Optional)<\/strong><\/p>\n<p>While not strictly required, you can configure Drools properties in your <code>application.yml<\/code> or <code>application.properties<\/code> file. This allows you to customize settings like logging levels and rule execution behavior.<\/p>\n<pre><code class=\"language-yaml\">drools:\n  kbase:\n    default:\n      default-kiesession:\n        type: stateless\n<\/code><\/pre>\n<p>This guide provides a basic framework for integrating Drools with your Spring Boot microservice. You can expand on this by exploring more advanced Drools features like decision tables, event processing, and complex event processing (CEP). Remember to adapt the rules and domain models to your specific business requirements.<\/p>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":3789,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[443],"tags":[],"series":[],"class_list":["post-3778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring_ai"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752622_1280-png.avif","jetpack-related-posts":[{"id":3780,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-jess-with-a-spring-boot-microservice\/","url_meta":{"origin":3778,"position":0},"title":"Integrating Jess with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"This post explores how to integrate the Jess rule engine with your Spring Boot microservice. We\u2019ll cover adding the necessary dependency, configuring Jess, and creating a service to utilize it. 1. Project Setup and Dependency Begin by creating a Spring Boot project. Then, add the Jess dependency to your pom.xml\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752536_1280-png.avif 3x"},"classes":[]},{"id":3782,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-rulebook-with-a-spring-boot-microservice\/","url_meta":{"origin":3778,"position":1},"title":"Integrating RuleBook with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"This post guides you through integrating the RuleBook rule engine with your Spring Boot microservice. We\u2019ll cover adding the dependency, configuring RuleBook, and creating a service to utilize it. 1. Project Setup and Dependency Start by creating a Spring Boot project. Next, add the RuleBook dependency to your pom.xml (Maven)\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/board-3772063_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/board-3772063_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/board-3772063_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/board-3772063_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/board-3772063_1280-jpg.avif 3x"},"classes":[]},{"id":3786,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-easy-rules-with-a-spring-boot-microservice\/","url_meta":{"origin":3778,"position":2},"title":"Integrating Easy Rules with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"This post will walk you through integrating the lightweight and straightforward Easy Rules engine with your Spring Boot microservice. We'll cover the necessary dependencies, basic setup, and an example service to demonstrate its usage. 1. Project Setup and Dependencies Start by creating a Spring Boot project. Next, add the following\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/office-4249395_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/office-4249395_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/office-4249395_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/office-4249395_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/office-4249395_1280-jpg.avif 3x"},"classes":[]},{"id":3784,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-openl-tablets-with-a-spring-boot-microservice\/","url_meta":{"origin":3778,"position":3},"title":"Integrating OpenL Tablets with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"This post explains how to integrate OpenL Tablets with your Spring Boot microservice. We'll cover adding the necessary dependencies, configuring OpenL Tablets, and creating a service to use it. 1. Project Setup and Dependencies Begin by creating a Spring Boot project. Then, add the following OpenL Tablets dependencies to your\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/business-1754904_1280-jpg.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/business-1754904_1280-jpg.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/business-1754904_1280-jpg.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/business-1754904_1280-jpg.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/business-1754904_1280-jpg.avif 3x"},"classes":[]},{"id":3444,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-boot-admin-server-with-spring-cloud-discovery\/","url_meta":{"origin":3778,"position":4},"title":"Spring Boot Admin Server with Spring Cloud Discovery","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Boot Admin Server is a powerful tool for monitoring and managing Spring Boot applications. It provides a centralized dashboard for viewing application health, metrics, and logs. Spring Cloud Discovery, on the other hand, enables service registration and discovery for microservices-based applications. By integrating Spring Boot Admin Server with Spring\u2026","rel":"","context":"In &quot;Spring Discovery&quot;","block_context":{"text":"Spring Discovery","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_discovery\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/manhattan-3866140_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3569,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-prolog-with-spring-boot\/","url_meta":{"origin":3778,"position":5},"title":"Integrating Prolog with Spring Boot","author":"Jeffery Miller","date":"September 22, 2025","format":false,"excerpt":"Prolog, a declarative logic programming language, shines in solving specific types of problems that require knowledge representation and logical inference. Integrating Prolog with Spring Boot can bring the power of logic programming to your Java applications. 1. Setting Up Your Environment Add JPL Dependency: Include the Java Prolog Interface (JPL)\u2026","rel":"","context":"In &quot;Spring AI&quot;","block_context":{"text":"Spring AI","link":"https:\/\/www.mymiller.name\/wordpress\/category\/spring_ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/06\/Gemini_Generated_Image_avkkoeavkkoeavkk.jpg?fit=1200%2C1200&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/06\/Gemini_Generated_Image_avkkoeavkkoeavkk.jpg?fit=1200%2C1200&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/06\/Gemini_Generated_Image_avkkoeavkkoeavkk.jpg?fit=1200%2C1200&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/06\/Gemini_Generated_Image_avkkoeavkkoeavkk.jpg?fit=1200%2C1200&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/06\/Gemini_Generated_Image_avkkoeavkkoeavkk.jpg?fit=1200%2C1200&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/comments?post=3778"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3778\/revisions"}],"predecessor-version":[{"id":3779,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3778\/revisions\/3779"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3789"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3778"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}