JBPM和Spring 集成时需要在applicationContext.xml如下配置:
<bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
<constructor-arg value="jbpm.cfg.xml" />
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService"/>
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/>
但由于jbpmConfiguration和processEngine都实现了同一个接口org.jbpm.api.ProcessEngine, spring容器不知道应该使用哪一个bean ,因此会报出如下错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.jbpm.api.ProcessEngine] is defined: expected single matching bean but found 2: [jbpmConfiguration, processEngine]
解决方式:
使用注解@Qualifier指定具体的bean
@Autowired
@Qualifier("processEngine")
private ProcessEngine processEngine;