我很难建立一个jBPM7项目。我正在尝试将jBPM引擎与H2内存数据库一起使用,以利用人工任务服务。我已如下设置数据源,实体管理器工厂和事务管理器:

application.properties

...
jbpm.datasource.jdbc-url=jdbc:h2:mem:testdb
jbpm.datasource.username=sa
jbpm.datasource.password=
...


JbpmDataConfiguration.java

@Configuration
@EnableTransactionManagement
public class JbpmDataConfiguration {
    @Bean(name = "jbpmDataSource")
    @ConfigurationProperties(prefix = "jbpm.datasource")
    public DataSource dataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "jbpmEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean jbpmEntityManagerFactory(EntityManagerFactoryBuilder builder, @Qualifier("jbpmDataSource") DataSource dataSource) {
        Map<String, String> properties = new HashMap<>();
        properties.put("hibernate.hbm2ddl.auto", "create");
        return builder.dataSource(dataSource)
            .mappingResources("META-INF/Taskorm.xml")
            .packages("org.jbpm.services.task.impl.model")
            .persistenceUnit("jbpm-persistence-unit")
            .properties(properties)
            .build();
    }

    @Bean(name = "jbpmTransactionManager")
    public JpaTransactionManager jbpmTransactionManager(@Qualifier("jbpmEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
        JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
        jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
        return jpaTransactionManager;
    }
}


在我的资源文件夹中,在resources / META-INF /中有一个kmodule.xml。我所有的.bpmn文件都位于resources / com / mydomain / flow /

<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
    <kbase name="kbase" packages="com.mydomain.flow" />
</kmodule>


然后,我使用以下命令创建运行时引擎:

@Configuration
public class MyRuntimeEngine {

    @Autowired
    @Qualifier("jbpmEntityManagerFactory")
    private EntityManagerFactory entityManagerFactory;

    @Autowired
    @Qualifier("jbpmTransactionManager")
    private JpaTransactionManager transactionManager;

    @Bean
    public RuntimeManager runtimeManager() {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kieContainer = kieServices.getKieClasspathContainer();
        KieBase kieBase = kieContainer.getKieBase("kbase");

        RuntimeEnvironmentBuilder runtimeEnvironmentBuilder = RuntimeEnvironmentBuilder.Factory.get()
            .newDefaultInMemoryBuilder()
            .entityManagerFactory(entityManagerFactory)
            .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, transactionManager);
        RuntimeEnvironment runtimeEnvironment = runtimeEnvironmentBuilder.knowledgeBase(kieBase).get();
        return RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(runtimeEnvironment);
    }
}


我将RuntimeManager bean自动装配到另一个配置类中,以便可以配置全局变量和工作项处理程序。完成后,这将公开一个KieSession bean。为了开始一个过程,我将KieSession自动装配到我的一个控制器中,并调用startProcess:

kieSession.startProcess(processName, processVariables);


导致以下错误:

javax.persistence.TransactionRequiredException: No local transaction to join
        at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.doJoinTransaction(ExtendedEntityManagerCreator.java:391) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
        at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:333) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
        at com.sun.proxy.$Proxy160.joinTransaction(Unknown Source) ~[na:na]
        at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.joinTransaction(JPAWorkingMemoryDbLogger.java:318) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.persist(JPAWorkingMemoryDbLogger.java:246) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.audit.JPAWorkingMemoryDbLogger.afterVariableChanged(JPAWorkingMemoryDbLogger.java:133) ~[jbpm-audit-7.22.0.Final.jar:7.22.0.Final]
        at org.drools.core.event.ProcessEventSupport.fireAfterVariableChanged(ProcessEventSupport.java:155) ~[drools-core-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.context.variable.VariableScopeInstance.setVariable(VariableScopeInstance.java:114) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.AbstractProcessInstanceFactory.createProcessInstance(AbstractProcessInstanceFactory.java:59) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:260) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:242) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.ProcessRuntimeImpl.createProcessInstance(ProcessRuntimeImpl.java:200) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:190) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
        at org.jbpm.process.instance.ProcessRuntimeImpl.startProcess(ProcessRuntimeImpl.java:185) ~[jbpm-flow-7.22.0.Final.jar:7.22.0.Final]
...


如何正确配置事务管理器以与jBPM一起使用?

最佳答案

我在设置JBPM 7.x版本时也遇到了同样的麻烦。您是否能够使JBPM与JPA事务管理器一起运行...从官方文档中看来,如果需要在嵌入式模式下使用JBPM,则我们需要外部事务管理器实现(如Narayanan或bitronix)

10-08 08:38