假设我有一条路线
import org.apache.camel.builder.RouteBuilder;
class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("file:src/data?noop=true")
.transacted()
.bean("accountService","credit")
.bean("accountService","debit");
}
}正如您所看到的,我正在使用transacted(),我知道如何选择事务传播策略,即REQUIRED_NEW、PROPAGATION_MANDATORY等。
但是,我不知道如何更改transacted()隔离级别,即如何将其设置为隔离级别SERIALIZABLE
备注:
我正在使用
JAVA 11
SpringBoot 2.4.5
Apache Camel 3.7.3发布于 2021-05-03 21:12:07
如果您想尝试自定义隔离级别,我认为您必须创建一个SpringTransactionPolicy并提供一个TransactionTemplate实例:请参阅here
执行此操作后,您将能够specify所需的隔离级别:
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
SpringTransactionPolicy customPolicy = new SpringTransactionPolicy(transactionTemplate);
from("...")
.policy(customPolicy)发布于 2021-05-03 18:22:23
被事务处理的方法可以引用保存所希望的事务策略的特定bean:
.transacted("PROPAGATION_REQUIRED")或者,在SpringRouteBuilder的情况下,您可以使用Policy对象:
public void configure() {
Policy myPolicy = bean(SpringTransactionPolicy.class, "PROPAGATION_REQUIRES_NEW"));
...
from("...")
.policy(myPolicy)https://stackoverflow.com/questions/67366739
复制相似问题