Accessing Spring beans from jBPM actions

Another important feature of Spring Modules jBPM integration is allowing Spring configured beans to be reused inside jBPM actions. This allows one to leverage Spring container capabilities (bean lifecycles, scoping, injection, proxying just to name a few) in a transparent way with jBPM. Consider the following Spring application context:

<beans>
 <!-- Spring bean visible inside jBPM processed -->
 <bean id="jbpmAction" class="org.MyJbpmActionHandler" singleton="true">
   <property name="someProp" ref="anotherBean"/>   <!-- this step can resolve the roleName property injection --->    <property name="roleName" value="" />    </bean> </beans>
 
 

and jBPM process definition:

<?xml version="1.0" encoding="UTF-8"?>

<process-definition name="simpleWorkflow">
 <start-state>
  <transition to="myState">
  </transition>
 </start-state>

 <state name="myState">
  <transition to="end">
   <action name="myAction" config-type="bean" 
      class="org.springmodules.workflow.jbpm31.JbpmHandlerProxy">
    <targetBean>jbpmAction</targetBean><!-- fault <roleName>admin</roleName> --->     <factoryKey>jbpmConfiguration</factoryKey>
   </action>
  </transition>
 </state>

 <end-state name="end"/>
</process-definition>
 
 

JbpmHandlerProxy transparently locates Spring applicationContext and searches the bean identified by the targetBean parameter (in this case jbpmAction) and delegate all calls to the jBPM action. This way, one is not limited only to the injection offered by jBPM container and can integrate and communicate in a very easy manner with other Spring managed beans. Moreover, your action lifecycle can be sigleton (one shared instance) or prototype (every call gets a new instance) or in Spring 2.0 scoped to a certain application component (like one instance per http session).

The optional factoryKey parameter specified in this example should be used when one is dealing with more then one jBPM configuration inside the same classloader (not common in practice). The factoryKey should be the same as the bean name of the LocalJbpmConfigurationFactoryBean to be used (in our case jbpmConfiguration).

你可能感兴趣的:(Accessing Spring beans from jBPM actions)