从alfresco activiti过程中调用spring bean

时间:2011-10-26 07:24:50

标签: spring javabeans alfresco activiti

在alfresco activiti中,我可以使用servicetask调用spring bean,如:

<serviceTask id="assignApplicationId" name="Assign Application Id" 
  activiti:expression="${sequenceUtil.getOutboundId(task.id)}" 
  activiti:resultVariable="OutboundWF_ApplicationNumber"/>

但是,在我的自定义上下文中,我将sequenceUtil声明为:

<bean id="sequenceUtil" name="sequenceUtil" class="com.tts.mersal.presentation.bean.dialog.util.SequenceUtil">
    <property name="searchService">
        <ref bean="searchService" />
    </property>
    <property name="nodeService">
        <ref bean="nodeService" />
    </property>
    <property name="workflowService">
        <ref bean="WorkflowService" />
    </property>     
</bean>

实际上我得到了以下异常

org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'sequenceUtil'
at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:46)

2 个答案:

答案 0 :(得分:2)

我明白了:)

我必须覆盖activitiProcessEngineConfiguration bean以在bean属性

中包含我的自定义bean
<!-- -->
<!-- Activiti Process Engine -->
<!-- -->
<bean id="activitiProcessEngineConfiguration"
    class="org.alfresco.repo.workflow.activiti.AlfrescoProcessEngineConfiguration">
    <property name="dataSource" ref="wrappedDataSource" />
    <property name="transactionManager" ref="transactionManager" />
    <property name="databaseSchemaUpdate" value="${db.schema.update}" />
    <property name="history" value="full" />
    <property name="jobExecutorActivate" value="true" />

<!-- Limit the visible beans in expressions -->


<property name="beans">
    <map>
        <entry key="services" value-ref="ServiceRegistry" />
        <entry key="sequenceUtil" value-ref="sequenceUtil" />
    </map>    
</property>

    <property name="customTypes">
        <list>
            <ref bean="activitiScriptNodeType" />
            <ref bean="activitiScriptNodeListType" />
        </list>
    </property>
    <property name="customPreBPMNParseListeners">
        <list>
            <ref bean="activitiParseListener" />
        </list>
    </property>
</bean>

答案 1 :(得分:1)

有一种更好的方法可以将bean名称映射到el epressions。至少alfresco 5.2

最初activitiProcessEngineConfiguration定义如下:

<bean id="activitiProcessEngineConfiguration" class="org.alfresco.repo.workflow.activiti.AlfrescoProcessEngineConfiguration">

        <!-- Limit the visible beans in expressions -->
        <property name="beans" ref="activitiBeanRegistry" />
</bean>

activitiBeanRegistry定义如下:

<util:map id="activitiBeanRegistry" map-class="java.util.HashMap">
    <entry key="services" value-ref="ServiceRegistry" />
</util:map>

因此,您可以轻松添加您的bean名称,而无需触及原始activitiProcessEngineConfiguration。像那样:

<bean id="my.activitiBeanRegistry"  class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" depends-on="activitiBeanRegistry">
<property name="targetObject">
  <ref bean="activitiBeanRegistry" />
</property>
<property name="targetMethod" value="put" />
<property name="arguments">
  <list>
    <value>sequenceUtil</value>
    <ref bean="sequenceUtil" />
   </list>
</property>

打开延期关闭以进行修改:)

可以找到完整的来源here

另见activiti-context.xml