Dynamically updating JBoss Rules with Spring

JBoss Rules or formally know as Drools is a popular open source Rules Engine, it is “augmented implementation of Charles Forgy’s Rete algorithm tailored for the Java language.” I have used it for the past 2 years in various projects and have come to like it below is a list of things I like about Drools

  1. It is open source, which will help you overcome a major obstacle when trying to introduce into a project.
  2. It is light, by that I mean you do not need a dedicated server to just host a rules engine or learn a new tool, it just another Jar file you add to your existing project.
  3. Plays well with Spring, now this is a winning combination for me cause I love the Spring Framework (Spring just makes life easy).

I am not going to go in dept about using Drools with Spring you can read my other post about it, what I want to talk about today is how you would dynamically update Rules, here is my setup.

A Rules POJO


	/** returns an instance of the Rules Base */

	/** initializes an instance of a Rules Base object by reading files from a specific directory */


Make sure the RulesService is a singleton which it should be by default when you are using Spring, your spring config should look something like this.


	<bean id="rulesService" class="edu.apollogrp.qtask.RulesService" init-method="init">
		<!-- where to the files are stored -->
		<property name="drlResourcePath" value="RulesDirectory"/>

This will make sure that as soon as your context starts, the RulesService POJO will start up and initialize a Rules Base Object by reading files (usually DRL or Decision Tables) from some specified directory (we will call this RulesDirectory) on the hard disk. RulesBase is a thread safe object so no worries there.

Calling Services

All services that need to execute rules should be injected with the RulesService POJO and use the RulesService to get the instance of the RulesBase and then create a working memory using it


	RulesService rulesService;

		final WorkingMemory workingMemory = rulesService.getRulesBase().newWorkingMemory();

	setRulesService(RulesService rulesService)
		this.rulesService = rulesService


Create an Action class and inject it with the RulesService, this Action class when executed should call the RulesService.init() method, make sure this action is only allowed to some super user.

That it! now anytime you can deploy new rule files into the RulesDirectory and call the refresh action and it will immediately take effect.

2 thoughts on “Dynamically updating JBoss Rules with Spring

  1. you do it by yourself!
    It is magic!

    in the new drools version, there is drools knowledge agent which can do the same thing.

  2. hi
    i am shifting form to drools rules engine i need to show all my rulesin drl file on gui how can i do that

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s