Here is how I create StatefulKnowledgeSession instances dynamically, while still leveraging Spring config:<div><br></div><div>[...]</div><div><br></div><div><div>  &lt;drools:ksession kbase=&quot;kBase&quot; type=&quot;stateful&quot; id=&quot;kSessionParent&quot;&gt;</div>
<div>    &lt;drools:batch&gt;</div><div>      &lt;drools:set-global identifier=&quot;helper&quot; ref=&quot;sessionHelper&quot;/&gt;</div><div>    &lt;/drools:batch&gt;</div><div>  &lt;/drools:ksession&gt;</div><div><br></div>
<div>  &lt;bean id=&quot;kSession&quot; scope=&quot;prototype&quot; parent=&quot;kSessionParent&quot;/&gt;</div><div><br></div><div>  &lt;bean id=&quot;knowledgeSessionGateway&quot; class=&quot;com.acme.rules.CompositeKnowledgeSessionGateway&quot;&gt;</div>
<div>    &lt;lookup-method name=&quot;createSession&quot; bean=&quot;kSession&quot;/&gt;</div><div>  &lt;/bean&gt;</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 &quot;abstract&quot; attribute does not seem to be supported on &lt;drools:ksession&gt;. 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">&lt;<a href="mailto:Herman.Post@imail.org">Herman.Post@imail.org</a>&gt;</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>