2015-06-09 67 views
1

我試圖整合Spring和JBPM6,但使用根據https://github.com/droolsjbpm/droolsjbpm-integration/tree/6.1.0.Final/kie-spring/src/test/resources/jbpm/local-emf配置基於Java風格的配置,但創建RuntimeEviromentFactoryBean時,在這裏得到了無法解決的循環引用錯誤列表我的配置春Jbpm6集成問題

DataConfig。 java的

@Configuration 
@EnableJpaRepositories(basePackages = { "com.test.spring.config.repository" }) 
@EnableTransactionManagement 
public class DataConfig { 
@Bean 
public DataSource devDataSource() { 
    HikariConfig config = new HikariConfig(); 
    config.setJdbcUrl("jdbc:h2:mem:spring-jbpm"); 
    config.setUsername("jbpm"); 
    config.setPassword("jbpm); 
    config.setDriverClassName("org.h2.Driver"); 
    return new HikariDataSource(config); 
} 

@Bean 
@Autowired 
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
     DataSource datasource) { 
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); 
    emf.setDataSource(datasource); 
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); 
    hibernateJpaVendorAdapter.setShowSql(true); 
    emf.setJpaVendorAdapter(hibernateJpaVendorAdapter); 
    emf.setPackagesToScan("org.jbpm.persistence.processinstance", 
      "org.drools.persistence.info", "org.jbpm.process.audit", 
      "org.jbpm.persistence.correlation", 
      "org.jbpm.runtime.manager.impl.jpa", 
      "org.jbpm.services.task.impl.model", 
      "org.jbpm.services.task.audit.impl.model"); 
    emf.setJpaPropertyMap(getJpaProperties()); 
    emf.setMappingResources("META-INF/Taskorm.xml", 
      "META-INF/TaskAuditorm.xml"); 
    return emf; 
} 

private Map<String, ?> getJpaProperties() { 
    Map<String, Object> p = new HashMap<String, Object>(); 
    p.put("hibernate.max_fetch_depth", 3); 
    p.put("hibernate.hbm2ddl.auto", "create"); 
    p.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); 
    p.put("hibernate.id.new_generator_mappings", false); 
    return null; 

} 

@Bean 
@Autowired 
public PlatformTransactionManager transactionManager(
     EntityManagerFactory emf) throws NamingException { 
    return new JpaTransactionManager(emf); 
} 

@Bean 
@Autowired 
public EntityManager entityManager(EntityManagerFactory emf) { 
    return emf.createEntityManager(); 
} 

JbpmConfig.java

@Configuration 
public class JbpmConfig { 

@Bean 
@Autowired 
public RuntimeEnvironmentFactoryBean runtimeEnvironmentFactoryBean(
     EntityManagerFactory emf, PlatformTransactionManager tm) { 

    RuntimeEnvironmentFactoryBean ref = new RuntimeEnvironmentFactoryBean(); 

    ref.setType("DEFAULT"); 
    ref.setEntityManagerFactory(emf); 
    ref.setTransactionManager(tm); 
    // ref.setKbaseName("kbase"); 
    ref.setAssets(getAssets()); 
    return ref; 

} 

// @Bean 
// @Autowired 
// public RuntimeEnvironment runtimeEnvironment(
// RuntimeEnvironmentFactoryBean ref) throws Exception { 
// return (RuntimeEnvironment) ref.getObject(); 
// } 

// @Bean 
// @Autowired 
// public RuntimeManagerFactoryBean runtimeManagerFactoryBean(
// RuntimeEnvironment re) { 
// RuntimeManagerFactoryBean rmf = new RuntimeManagerFactoryBean(); 
// rmf.setIdentifier("spring-rm"); 
// rmf.setRuntimeEnvironment(re); 
// rmf.setType("PER_PROCESS_INSTANCE"); 
// return rmf; 
// } 

// @Bean 
// @Autowired 
// public TaskServiceFactoryBean taskServiceFactoryBean(
// EntityManagerFactory emf, PlatformTransactionManager tm) { 
// TaskServiceFactoryBean tsf = new TaskServiceFactoryBean(); 
// tsf.setEntityManagerFactory(emf); 
// tsf.setTransactionManager(tm); 
// return tsf; 
// } 

// @Bean 
// @Autowired 
// public JPAAuditLogService logService(EntityManagerFactory emf) { 
// JPAAuditLogService logService = new JPAAuditLogService(emf); 
// return logService; 
// 
// } 

private Map<Resource, ResourceType> getAssets() { 
    Map<Resource, ResourceType> assets = new HashMap<Resource, ResourceType>(); 
    assets.put(ResourceFactory 
      .newClassPathResource("jbpm/processes/sample.bpmn"), 
      ResourceType.BPMN2); 
    return assets; 
} 

錯誤STA cktrace:

15:43:09.290 DEBUG Creating shared instance of singleton bean 'runtimeEnvironmentFactoryBean' -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.292 WARN Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'runtimeEnvironmentFactoryBean': Requested bean is currently in creation: Is there an unresolvable circular reference? -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.293 DEBUG Returning cached instance of singleton bean 'entityManagerFactory' -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.293 DEBUG Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor' -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.295 DEBUG Creating shared instance of singleton bean 'runtimeEnvironmentFactoryBean' -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.295 WARN Bean creation exception on FactoryBean type check: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'runtimeEnvironmentFactoryBean': Requested bean is currently in creation: Is there an unresolvable circular reference? -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.296 DEBUG Creating shared instance of singleton bean 'transactionManager' -- o.s.b.f.s.DefaultListableBeanFactory 
15:43:09.297 WARN Exception encountered during context initialization - cancelling refresh attempt -- o.s.w.c.s.AnnotationConfigWebApplicationContext 
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference? 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:347) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1127) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:816) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:744) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:860) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:790) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:541) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:436) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1112) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:816) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:744) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
... 30 more 
Wrapped by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'runtimeEnvironmentFactoryBean' defined in class path resource [com/spring/jbpm/config/JbpmConfig.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.transaction.PlatformTransactionManager]: : Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference?; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference? 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:752) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:860) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:790) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:541) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:436) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:412) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1112) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:816) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:744) ~[spring-beans-4.1.3.RELEASE.jar:4.1.3.RELEASE] 
... 30 more 
+0

嗯,我使用Spring 4.x,它是否與jbpm6衝突? – nanfengbobo

回答

1

好,之後我改變了我的配置,它的工作原理,代碼如下

DataConfig.java

@Configuration 
@EnableJpaRepositories(basePackages = { "com.test.spring.config.repository" }) 
@EnableTransactionManagement 
public class DataConfig { 
@Bean 
public DataSource devDataSource() { 
    HikariConfig config = new HikariConfig(); 
    config.setJdbcUrl("jdbc:h2:mem:spring-jbpm"); 
    config.setUsername("jbpm"); 
    config.setPassword("jbpm); 
    config.setDriverClassName("org.h2.Driver"); 
    return new HikariDataSource(config); 
} 

@Bean 
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { 
    LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); 
    emf.setDataSource(dataSource()); 
    HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); 
    hibernateJpaVendorAdapter.setShowSql(true); 
    emf.setJpaVendorAdapter(hibernateJpaVendorAdapter); 
    emf.setPackagesToScan("org.jbpm.persistence.processinstance", 
      "org.drools.persistence.info", "org.jbpm.process.audit", 
      "org.jbpm.persistence.correlation", 
      "org.jbpm.runtime.manager.impl.jpa", 
      "org.jbpm.services.task.impl.model", 
      "org.jbpm.services.task.audit.impl.model"); 
    emf.setJpaPropertyMap(getJpaProperties()); 
    emf.setMappingResources("META-INF/JBPMorm.xml","META-INF/Taskorm.xml", 
      "META-INF/TaskAuditorm.xml"); 
    return emf; 
} 

private Map<String, ?> getJpaProperties() { 
    Map<String, Object> p = new HashMap<String, Object>(); 
    p.put("hibernate.max_fetch_depth", 3); 
    p.put("hibernate.hbm2ddl.auto", "create"); 
    p.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); 
    p.put("hibernate.id.new_generator_mappings", false); 
    return p; 

} 

@Bean 
public PlatformTransactionManager transactionManager() throws NamingException { 
    return new JpaTransactionManager(entityManagerFactory().getObject()); 
} 

JbpmConfig.java

@Configuration 
public class JbpmConfig { 
@Autowired 
private EntityManagerFactory emf; 

@Autowired 
private PlatformTransactionManager tm; 

@Bean 
public RuntimeEnvironmentFactoryBean runtimeEnvironment() { 

    RuntimeEnvironmentFactoryBean ref = new RuntimeEnvironmentFactoryBean(); 

    ref.setType("DEFAULT"); 
    ref.setEntityManagerFactory(emf); 
    ref.setTransactionManager(tm); 
    // ref.setKbaseName("kbase"); 
    ref.setAssets(getAssets()); 
    return ref; 

} 

@Bean(name = "runtimeManager", destroyMethod = "close") 
public RuntimeManagerFactoryBean runtimeManager() { 
    RuntimeManagerFactoryBean rmf = new RuntimeManagerFactoryBean(); 
    rmf.setIdentifier("spring-rm"); 
    try { 
     rmf.setRuntimeEnvironment((RuntimeEnvironment) runtimeEnvironment() 
       .getObject()); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    rmf.setType("PER_PROCESS_INSTANCE"); 
    return rmf; 
} 

@Bean 
public TaskServiceFactoryBean taskServiceFactoryBean() { 
    TaskServiceFactoryBean tsf = new TaskServiceFactoryBean(); 
    tsf.setEntityManagerFactory(emf); 
    tsf.setTransactionManager(tm); 
    return tsf; 
} 

private Map<Resource, ResourceType> getAssets() { 
    Map<Resource, ResourceType> assets = new HashMap<Resource, ResourceType>(); 
    assets.put(ResourceFactory 
      .newClassPathResource("jbpm/processes/sample.bpmn"), 
      ResourceType.BPMN2); 
    return assets; 
} 
+0

嗨,我工作jBPM內的一個jHipster web應用程序的集成,並得到了一些問題,也許你已經回答了。我應該同時保持事務管理器和數據訪問定義嗎?我的意思是整個應用程序的事務範圍與jBPM範圍完全不同,並且,如何告訴jBPM從哪裏獲取用戶數據?我剛剛看到這個,它有一個從spring獲取數據的類,這是正確的方向嗎?謝謝。 –