[rules-users] Question about Drools Spring, StatelessKnowledgeSession and globals
Patrick van Kann
pvankann at gmail.com
Fri Oct 29 11:33:44 EDT 2010
Hello,
I've been trying out the Spring integration package in Drools 5.1.1 and it
works really well, but I have run into one issue I can't figure out.
I've defined 2 knowledge sessions from the same knowledge base in the app
context - one stateless, one stateful but otherwise identical. They both
refer to a collaborator defined as a bean in the app context which is to be
used as a global in my rules. This is just an excerpt of my full Spring
context, the kbase definition itself is not an issue.
<bean id="applicantDao" class="com.acme.app.dao.impl.ApplicantDaoImpl" />
<drools:ksession id="statelessKSession" type="stateless"
name="statelessKSession" kbase="kbase">
<drools:script>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:script>
</drools:ksession>
<drools:ksession id="statefulKSession" type="stateful"
name="statefulKSession" kbase="kbase">
<drools:script>
<drools:set-global identifier="applicantDao" ref="applicantDao" />
</drools:script>
</drools:ksession>
The issue is that this configuration works for the stateful but not the
stateless session, in the sense that the stateful session appears to have a
valid reference to the applicantDao object in the Globals object but the
stateless session doesn't.
@Test
public void testStatelessGlobal() {
Globals globals = statelessKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
@Test
public void testStatefulGlobal() {
Globals globals = statefulKSession.getGlobals();
Object global = globals.get("applicantDao");
Assert.assertNotNull(global);
}
The first test fails (the global variable is null) but the second passes. No
errors are thrown by Drools during the setup of the Spring container.
What am I doing wrong? Should I be able to define globals in this way for
stateless sessions? The XSD seems to indicate this is a valid configuration,
but it just doesn't work.
Is anyone else working with the Spring integration that can point out my
error here?
Many thanks,
Patrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101029/c36997e9/attachment.html
More information about the rules-users
mailing list