Here is how I create StatefulKnowledgeSession instances dynamically, while still leveraging Spring config:<div><br></div><div>[...]</div><div><br></div><div><div> <drools:ksession kbase="kBase" type="stateful" id="kSessionParent"></div>
<div> <drools:batch></div><div> <drools:set-global identifier="helper" ref="sessionHelper"/></div><div> </drools:batch></div><div> </drools:ksession></div><div><br></div>
<div> <bean id="kSession" scope="prototype" parent="kSessionParent"/></div><div><br></div><div> <bean id="knowledgeSessionGateway" class="com.acme.rules.CompositeKnowledgeSessionGateway"></div>
<div> <lookup-method name="createSession" bean="kSession"/></div><div> </bean></div><div><br></div><div>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</div>
<div><br></div><div><div><div> protected StatefulKnowledgeSession createSession() {</div><div> return null;</div><div> }</div></div></div><div><br></div><div>method (that could be abstract) that gets overridden in a Spring-generated subclass.</div>
<div><br></div><div>Ref.:</div><div>[1] <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-method-injection">http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-factory-method-injection</a></div>
<div>[2] <a href="http://blog.springsource.com/2004/08/06/method-injection/">http://blog.springsource.com/2004/08/06/method-injection/</a></div><div><br></div><div>-Richard</div><br><div class="gmail_quote">On Wed, Jan 11, 2012 at 4:37 PM, Hrumph <span dir="ltr"><<a href="mailto:Herman.Post@imail.org">Herman.Post@imail.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is it possible to dynamically create a KnowledgeSession using the<br>
Drools-server API, or must the be statically declared in the Spring config?<br>
<br>
Thanks<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools.46999.n3.nabble.com/Drools-server-KnowledgeSessions-tp3652344p3652344.html" target="_blank">http://drools.46999.n3.nabble.com/Drools-server-KnowledgeSessions-tp3652344p3652344.html</a><br>
Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</font></blockquote></div><br></div>