关闭jbpm事务处理 xml配置
时间: 2023-10-22 18:08:57 浏览: 47
要关闭JBPM事务处理,您可以在JBPM的XML配置文件中将事务管理器设置为“无事务管理器”。以下是示例配置文件:
```
<jbpm-configuration>
<transaction-manager>none</transaction-manager>
<!-- 其他配置 -->
</jbpm-configuration>
```
通过将事务管理器设置为“none”,JBPM将不再使用任何事务管理器来处理事务。请注意,这可能会导致一些问题,例如如果您的流程需要处理事务,则它们将不再受到保护,因此请务必谨慎操作。
相关问题
配置JBPM的持久化服务不启用事务处理 xml配置
如果你希望在JBPM中配置持久化服务但不想使用事务处理,则可以在XML配置文件中进行如下配置:
首先,在`jbpm.cfg.xml`文件中添加以下代码:
```xml
<bean id="transactionManager" class="org.springframework.transaction.support.ResourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="packagesToScan" value="com.xxx.model"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
</props>
</property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributeSource">
<value>
public * com.xxx.service.*.*(..)
</value>
</property>
</bean>
<aop:config>
<aop:advisor advice-ref="transactionInterceptor" pointcut="execution(* com.xxx.service.*.*(..))"/>
</aop:config>
<bean id="jpaTaskService" class="org.jbpm.task.service.TaskService">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="transactionManager" ref="transactionManager"/>
</bean>
<bean id="jpaRuntimeManager" class="org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl" factory-method="newPerProcessInstanceRuntimeManager">
<constructor-arg ref="jpaEnvironment"/>
<constructor-arg>
<value>com.xxx:xxx-kjar:1.0</value>
</constructor-arg>
<constructor-arg>
<value>com.xxx.Main</value>
</constructor-arg>
<constructor-arg>
<null/>
</constructor-arg>
</bean>
<bean id="jpaEnvironment" class="org.kie.api.runtime.manager.RuntimeEnvironmentBuilder">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
<property name="userGroupCallback" ref="userGroupCallback"/>
<property name="taskService" ref="jpaTaskService"/>
<property name="registerableItemsFactory">
<bean class="org.jbpm.shared.services.impl.JbpmJTATransactionManagerFactory">
<property name="transactionManager" ref="transactionManager"/>
</bean>
</property>
</bean>
```
在上面的代码中,我们定义了一个`transactionManager` bean,它使用了一个数据源(`dataSource`)作为参数。这个数据源可以根据你的具体情况进行配置。
接下来,我们定义了一个`entityManagerFactory` bean,它使用了上面定义的数据源,并设置了一些JPA相关的配置。
然后,我们定义了一个`transactionInterceptor` bean,它用于拦截指定的服务方法,以便在方法执行时启用事务处理。在这个例子中,我们拦截了`com.xxx.service`包中的所有公共方法。
最后,我们定义了一个`jpaRuntimeManager` bean,它使用了上述定义的`jpaEnvironment`和其他一些配置参数。这个bean用于管理JBPM流程实例的生命周期。
注意,以上代码仅提供了一种基本的配置方式,具体的配置参数可能需要根据你的具体情况进行调整。
使用xml的方式配置呢?不使用注解
如果你想使用xml的方式配置声明式事务管理,可以在Spring的配置文件中加入以下内容:
```xml
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="myService" class="com.example.MyService">
<property name="jbpmTemplate" ref="jbpmTemplate"/>
</bean>
<bean id="jbpmTemplate" class="org.jbpm.api.JbpmTemplate">
<property name="configuration" ref="jbpmConfiguration"/>
</bean>
<bean id="jbpmConfiguration" class="org.jbpm.api.Configuration">
<property name="jbpmProperties">
<props>
<!-- 配置jbpm的属性 -->
</props>
</property>
</bean>
```
在以上配置中,`<tx:annotation-driven>`用于启用声明式事务管理,`transaction-manager`属性指定了事务管理器,`<bean>`元素定义了MyService、JbpmTemplate和JbpmConfiguration等bean,在这些bean的定义中可以通过`<property>`元素注入依赖关系。
如果你想使用xml的方式手动控制事务的边界,可以使用Spring提供的TransactionTemplate类。例如:
```xml
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="myService" class="com.example.MyService">
<property name="jbpmTemplate" ref="jbpmTemplate"/>
<property name="transactionTemplate" ref="transactionTemplate"/>
</bean>
<bean id="jbpmTemplate" class="org.jbpm.api.JbpmTemplate">
<property name="configuration" ref="jbpmConfiguration"/>
</bean>
<bean id="jbpmConfiguration" class="org.jbpm.api.Configuration">
<property name="jbpmProperties">
<props>
<!-- 配置jbpm的属性 -->
</props>
</property>
</bean>
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager"/>
</bean>
```
在以上配置中,`<bean>`元素定义了MyService、JbpmTemplate和JbpmConfiguration等bean,在这些bean的定义中可以通过`<property>`元素注入依赖关系。其中,`transactionManager`属性指定了事务管理器,`transactionTemplate`属性指定了事务模板。在MyService类中使用TransactionTemplate来控制事务的边界,例如:
```java
@Service
public class MyService {
@Autowired
private JbpmTemplate jbpmTemplate;
@Autowired
private TransactionTemplate transactionTemplate;
public void doSomething() {
transactionTemplate.execute(new TransactionCallback<Void>() {
@Override
public Void doInTransaction(TransactionStatus status) {
// 在这里执行业务逻辑
jbpmTemplate.execute(...);
return null;
}
});
}
}
```
这样写代码时,如果在transactionTemplate.execute方法内部出现异常,事务会自动回滚。如果在execute方法外部出现异常,事务也会回滚。