我尝试集成Spring和JBPM6,但是根据https://github.com/droolsjbpm/droolsjbpm-integration/tree/6.1.0.Final/kie-spring/src/test/resources/jbpm/local-emf的配置使用基于Java的样式配置,但在创建RuntimeEviromentFactoryBean时遇到无法解决的循环引用错误,这里列出我的配置
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;
}
错误堆栈跟踪:
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 :(得分: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;
}