Circular dependency while embedding jbpm 7.9 in spring boot 2.0.4
beingvikram Aug 11, 2018 12:37 PMI'm trying to embed jbpm 7.9 in a spring boot project, I've followed the instruction from the [official documentation][1], But instead of using xml configuration as in the document I'm using Spring Java Configuration class. The configuration class is as shown
@Configuration
public class JBPMConfiguration {
@Bean
public PropertiesFactoryBean roleProperties() {
PropertiesFactoryBean bean = new PropertiesFactoryBean();
bean.setLocation(new ClassPathResource("roles.properties"));
return bean;
}
@Bean
public JBossUserGroupCallbackImpl userGroupCallback(Properties roleProperties) {
return new JBossUserGroupCallbackImpl(roleProperties);
}
@Bean
public ClearBPMSecurityIdentityProvider identityProvider() {
return new ClearBPMSecurityIdentityProvider();
}
@Bean
public SpringRuntimeManagerFactoryImpl runtimeManagerFactory(JtaTransactionManager transactionManager,
JBossUserGroupCallbackImpl userGroupCallback) {
SpringRuntimeManagerFactoryImpl springRuntimeManagerFactoryImpl = new SpringRuntimeManagerFactoryImpl();
springRuntimeManagerFactoryImpl.setTransactionManager(transactionManager);
springRuntimeManagerFactoryImpl.setUserGroupCallback(userGroupCallback);
return springRuntimeManagerFactoryImpl;
}
@Bean
public TransactionalCommandService transactionCmdService(EntityManagerFactory entityManagerFactory) {
return new TransactionalCommandService(entityManagerFactory);
}
@Bean(destroyMethod = "close")
public TaskServiceFactoryBean taskService(EntityManagerFactory entityManagerFactory,
JtaTransactionManager transactionManager, UserGroupCallback userGroupCallback) {
TaskServiceFactoryBean taskServiceFactoryBean = new TaskServiceFactoryBean();
taskServiceFactoryBean.setEntityManagerFactory(entityManagerFactory);
taskServiceFactoryBean.setTransactionManager(transactionManager);
taskServiceFactoryBean.setUserGroupCallback(userGroupCallback);
TaskLifeCycleEventListener taskLifeCycleEventListener = new JPATaskLifeCycleEventListener(true);
List<TaskLifeCycleEventListener> list = new ArrayList<>();
list.add(taskLifeCycleEventListener);
taskServiceFactoryBean.setListeners(list);
return taskServiceFactoryBean;
}
@Bean
public BPMN2DataServiceImpl definitionService() {
return new BPMN2DataServiceImpl();
}
@Bean
public RuntimeDataServiceImpl runtimeDataService(TransactionalCommandService transactionCmdService,
ClearBPMSecurityIdentityProvider identityProvider, TaskServiceFactoryBean taskService) throws Exception {
RuntimeDataServiceImpl runtimeDataServiceImpl = new RuntimeDataServiceImpl();
runtimeDataServiceImpl.setCommandService(transactionCmdService);
runtimeDataServiceImpl.setIdentityProvider(identityProvider);
runtimeDataServiceImpl.setTaskService((TaskService) taskService.getObject());
return runtimeDataServiceImpl;
}
@Bean(initMethod = "onInit")
@DependsOn("entityManagerFactory")
public KModuleDeploymentService deploymentService(DefinitionService definitionService,
EntityManagerFactory entityManagerFactory, RuntimeManagerFactory runtimeManagerFactory,
IdentityProvider identityProvider, RuntimeDataService runtimeDataService) {
KModuleDeploymentService kModuleDeploymentService = new KModuleDeploymentService();
kModuleDeploymentService.setBpmn2Service(definitionService);
kModuleDeploymentService.setEmf(entityManagerFactory);
kModuleDeploymentService.setManagerFactory(runtimeManagerFactory);
kModuleDeploymentService.setIdentityProvider(identityProvider);
kModuleDeploymentService.setRuntimeDataService(runtimeDataService);
return kModuleDeploymentService;
}
@Bean
@DependsOn(value = { "deploymentService" })
public ProcessServiceImpl processService(RuntimeDataService runtimeDataService,
DeploymentService deploymentService) {
ProcessServiceImpl processService = new ProcessServiceImpl();
processService.setDataService(runtimeDataService);
processService.setDeploymentService(deploymentService);
return processService;
}
@Bean
@DependsOn(value = { "deploymentService" })
public UserTaskServiceImpl userTaskService(RuntimeDataService runtimeDataService,
DeploymentService deploymentService) {
UserTaskServiceImpl userTaskService = new UserTaskServiceImpl();
userTaskService.setDataService(runtimeDataService);
userTaskService.setDeploymentService(deploymentService);
return userTaskService;
}
@Bean
@DependsOn(value = { "deploymentServices"})
public MethodInvokingFactoryBean data(RuntimeDataService runtimeDataService, DeploymentService deploymentService) {
MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
methodInvokingFactoryBean.setTargetObject(deploymentService);
methodInvokingFactoryBean.setTargetMethod("addListener");
ArrayList<RuntimeDataService> arrayList = new ArrayList<>();
arrayList.add(runtimeDataService);
methodInvokingFactoryBean.setArguments(arrayList);
return methodInvokingFactoryBean;
}
}
The server is not starting, I'm getting the below error, Please help
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
userGroupCallback defined in class path resource [tv/clearhub/bpm/configuration/JBPMConfiguration.class]
┌─────┐
| taskService defined in class path resource [tv/clearhub/bpm/configuration/JBPMConfiguration.class]
↑ ↓
| data defined in class path resource [tv/clearhub/bpm/configuration/JBPMConfiguration.class]
↑ ↓
| runtimeDataService defined in class path resource [tv/clearhub/bpm/configuration/JBPMConfiguration.class]
└─────┘