jbpm4.3 repositoryService circular reference 循环引用

http://yy629.iteye.com 日期: 2010-05-20

jbmp4.3 整合spring, 配置文件只注入processEngine 就没问题。
但是如果注入repositoryService , taskService等就会出现 Is there an unresolvable circular reference?

<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />


但注入repositoryService:
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" />

就报如下错误

Error creating bean with name 'repositoryService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public final org.jbpm.api.RepositoryService org.jbpm.pvm.internal.processengine.SpringProcessEngine$$EnhancerByCGLIB$$66ea6eb4.getRepositoryService()] threw exception; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'repositoryService': Requested bean is currently in creation: Is there an unresolvable circular reference?

分析原因是SpringProcessEngine.getRepositoryService会调用getBean的, 出现循环引用的错误

// SpringProcessEngine中的方法, getRepositoryService,getTaskService,等都是最终调用这个方法的
public <T> T get(Class<T> type) {
  String[] names = applicationContext.getBeanNamesForType(type);
  
  if (names.length >= 1) {
    
    if (names.length > 1 && log.isWarnEnabled()) {
      log.warn("Multiple beans for type " + type + " found. Returning the first result.");
    }
    
    return (T) applicationContext.getBean(names[0]); // 会出现循环引用错误
  }

  return super.get(type);
}


解决方案就是

方法1就是
<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" /> 
<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />

<bean id="processEngineWireContext" factory-bean="processEngine" factory-method="getProcessEngineWireContext" />

<bean id="repositoryService" factory-bean="processEngineWireContext" factory-method="get">
  <constructor-arg>
   <value type="java.lang.Class">org.jbpm.api.RepositoryService</value>
  </constructor-arg>
</bean>


方法2就是在写个工厂类, 通过processEngineWireContext构造出一个工厂类, 工厂类中有getRepositoryService,getTaskService等方法

你可能感兴趣的:(spring,xml,bean,jboss,jbpm)