Here is how I create StatefulKnowledgeSession instances dynamically, while
still leveraging Spring config:
[...]
<drools:ksession kbase="kBase" type="stateful"
id="kSessionParent">
<drools:batch>
<drools:set-global identifier="helper"
ref="sessionHelper"/>
</drools:batch>
</drools:ksession>
<bean id="kSession" scope="prototype"
parent="kSessionParent"/>
<bean id="knowledgeSessionGateway"
class="com.acme.rules.CompositeKnowledgeSessionGateway">
<lookup-method name="createSession" bean="kSession"/>
</bean>
Read [1,2] for background on Spring method injection and how to use it to
get a factory method for Spring-configured prototype beans without your
code (here: CompositeKnowledgeSessionGateway) needing to be Spring-aware.
Note that conceptually, kSessionParent is an abstract bean, but the
"abstract" attribute does not seem to be supported on <drools:ksession>.
Class CompositeKnowledgeSessionGateway has a
protected StatefulKnowledgeSession createSession() {
return null;
}
method (that could be abstract) that gets overridden in a Spring-generated
subclass.
Ref.:
[1]
http://static.springsource.org/spring/docs/3.0.x/spring-framework-referen...
[2]
http://blog.springsource.com/2004/08/06/method-injection/
-Richard
On Wed, Jan 11, 2012 at 4:37 PM, Hrumph <Herman.Post(a)imail.org> wrote:
Is it possible to dynamically create a KnowledgeSession using the
Drools-server API, or must the be statically declared in the Spring config?
Thanks
--
View this message in context:
http://drools.46999.n3.nabble.com/Drools-server-KnowledgeSessions-tp36523...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users