在spring boot 2.0.4中嵌入jbpm 7.9时的循环依赖

问题描述 投票:0回答:1

我试图在一个spring boot项目中嵌入jbpm 7.9,我按照[官方文档] [1]的说明进行操作,但是我没有使用xml配置,而是使用了Spring Java Configuration类。配置类如下所示

@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;

    }

}

服务器没有启动,我收到以下错误,请帮忙

***************************
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]
└─────┘
java spring-boot jbpm kie
1个回答
0
投票

请删除所有@DependsOn和(initMethod =“onInit”)。我的演示工作正常,但它们不是processService的参数,因为runtimeDataService和deploymentService在同一个类中,与其他元数相同。

© www.soinside.com 2019 - 2024. All rights reserved.