{"id":3786,"date":"2025-12-24T10:00:21","date_gmt":"2025-12-24T15:00:21","guid":{"rendered":"https:\/\/www.mymiller.name\/wordpress\/?p=3786"},"modified":"2025-12-24T10:00:21","modified_gmt":"2025-12-24T15:00:21","slug":"integrating-easy-rules-with-a-spring-boot-microservice","status":"publish","type":"post","link":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-easy-rules-with-a-spring-boot-microservice\/","title":{"rendered":"Integrating Easy Rules with a Spring Boot Microservice"},"content":{"rendered":"\n<p>This post will walk you through integrating the lightweight and straightforward Easy Rules engine with your Spring Boot microservice. We&#8217;ll cover the necessary dependencies, basic setup, and an example service to demonstrate its usage.<\/p>\n\n\n\n<p><strong>1. Project Setup and Dependencies<\/strong><\/p>\n\n\n\n<p>Start by creating a Spring Boot project. Next, add the following Easy Rules dependencies to your <code>pom.xml<\/code> (Maven) or <code>build.gradle<\/code> (Gradle) file:<\/p>\n\n\n\n<p><strong>Maven:<\/strong><\/p>\n\n\n\n<p>XML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;\n    &lt;groupId&gt;org.jeasy&lt;\/groupId&gt;\n    &lt;artifactId&gt;easy-rules-core&lt;\/artifactId&gt;\n    &lt;version&gt;5.3.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/code><\/pre>\n\n\n\n<p><strong>Gradle:<\/strong><\/p>\n\n\n\n<p>Gradle<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>implementation 'org.jeasy:easy-rules-core:5.3.0'\n<\/code><\/pre>\n\n\n\n<p><strong>2. Defining Rules with Easy Rules<\/strong><\/p>\n\n\n\n<p>Easy Rules promotes a POJO-based approach for defining rules. Create a class that implements the <code>org.jeasy.rules.api.Rule<\/code> interface:<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.jeasy.rules.annotation.Action;\nimport org.jeasy.rules.annotation.Condition;\nimport org.jeasy.rules.annotation.Rule;\n\n@Rule(name = \"Discount Rule\", description = \"Apply 10% discount for orders over $100\")\npublic class DiscountRule {\n\n    @Condition\n    public boolean isApplicable(Order order) {\n        return order.getTotalPrice() &gt; 100;\n    }\n\n    @Action\n    public void applyDiscount(Order order) {\n        order.applyDiscount(0.1);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>This code defines a rule named &#8220;Discount Rule&#8221;. The <code>isApplicable<\/code> method defines the condition (order total price greater than 100), and the <code>applyDiscount<\/code> method defines the action (apply a 10% discount).<\/p>\n\n\n\n<p><strong>3. Using Easy Rules in a Service<\/strong><\/p>\n\n\n\n<p>Inject the <code>RulesEngine<\/code> bean into your service class and use it to fire rules against your domain objects.<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.jeasy.rules.api.RulesEngine;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.stereotype.Service;\n\nimport java.util.Arrays;\n\n@Service\npublic class OrderService {\n\n    @Autowired\n    private RulesEngine rulesEngine;\n\n    public Order applyRules(Order order) {\n        rulesEngine.fire(Arrays.asList(new DiscountRule()), Arrays.asList(order));\n        return order;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>This service:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Injects the <code>RulesEngine<\/code> bean.<\/li>\n\n\n\n<li>Creates an instance of the <code>DiscountRule<\/code>.<\/li>\n\n\n\n<li>Fires the rule against the provided <code>order<\/code> object.<\/li>\n\n\n\n<li>Returns the modified <code>order<\/code> object.<\/li>\n<\/ul>\n\n\n\n<p><strong>4. Configuration Setup<\/strong><\/p>\n\n\n\n<p>Easy Rules has sensible defaults and often requires minimal configuration. You can customize the <code>RulesEngine<\/code> by defining your own bean:<\/p>\n\n\n\n<p>Java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import org.jeasy.rules.api.RulesEngineParameters;\nimport org.jeasy.rules.core.DefaultRulesEngine;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\n\n@Configuration\npublic class EasyRulesConfig {\n\n    @Bean\n    public RulesEngine rulesEngine() {\n        RulesEngineParameters parameters = new RulesEngineParameters()\n                .skipOnFirstAppliedRule(true); \/\/ Example parameter\n        return new DefaultRulesEngine(parameters);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>5. YML Changes (Not Required)<\/strong><\/p>\n\n\n\n<p>Easy Rules doesn&#8217;t typically require specific configuration in your <code>application.yml<\/code> or <code>application.properties<\/code> file.<\/p>\n\n\n\n<p>This guide provides a basic introduction to integrating Easy Rules with your Spring Boot microservice. Its simplicity and annotation-based approach make it easy to define and manage business rules. You can expand on this by exploring more advanced features like rule composition, priority, and custom rule listeners. Remember to tailor the rules and domain models to your specific business needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post will walk you through integrating the lightweight and straightforward Easy Rules engine with your Spring Boot microservice. We&#8217;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 Easy Rules dependencies to your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3793,"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-3786","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\/office-4249395_1280-jpg.avif","jetpack-related-posts":[{"id":3784,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-openl-tablets-with-a-spring-boot-microservice\/","url_meta":{"origin":3786,"position":0},"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":3778,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-drools-with-a-spring-boot-microservice\/","url_meta":{"origin":3786,"position":1},"title":"Integrating Drools with a Spring Boot Microservice","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"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. 1. Project Setup and Dependencies Start by creating a Spring Boot project using Spring Initializr or your preferred IDE.\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-1752622_1280-png.avif","width":350,"height":200,"srcset":"https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752622_1280-png.avif 1x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752622_1280-png.avif 1.5x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752622_1280-png.avif 2x, https:\/\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2024\/10\/rule-1752622_1280-png.avif 3x"},"classes":[]},{"id":3780,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_ai\/integrating-jess-with-a-spring-boot-microservice\/","url_meta":{"origin":3786,"position":2},"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":3786,"position":3},"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":3444,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-boot-admin-server-with-spring-cloud-discovery\/","url_meta":{"origin":3786,"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":3441,"url":"https:\/\/www.mymiller.name\/wordpress\/spring_discovery\/spring-cloud-gateway-with-spring-cloud-discovery\/","url_meta":{"origin":3786,"position":5},"title":"Spring Cloud Gateway with Spring Cloud Discovery","author":"Jeffery Miller","date":"December 24, 2025","format":false,"excerpt":"Spring Cloud Gateway and Spring Cloud Discovery are powerful tools for building microservices architectures. Spring Cloud Gateway acts as an API gateway, routing requests to the appropriate microservices. Spring Cloud Discovery provides a registry for microservices, enabling dynamic service discovery and load balancing. In this comprehensive guide, we'll delve into\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\/trees-2900064_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\/trees-2900064_640.jpg?fit=640%2C427&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.mymiller.name\/wordpress\/wp-content\/uploads\/2023\/11\/trees-2900064_640.jpg?fit=640%2C427&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3786","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=3786"}],"version-history":[{"count":1,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3786\/revisions"}],"predecessor-version":[{"id":3787,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/posts\/3786\/revisions\/3787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media\/3793"}],"wp:attachment":[{"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/media?parent=3786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/categories?post=3786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/tags?post=3786"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mymiller.name\/wordpress\/wp-json\/wp\/v2\/series?post=3786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}