在一个春季应用程序中,我们添加了一些AOP尖端来进行拦截,... JPA存储库的方法在每次插入实体时,更新实体时,都可以刷新含蓄的视图。
,但是,我们有一些批处理过程,需要大量时间调用thoses
save
方法。 (不,由于现有代码太复杂而无法重构时,不可能在批处理结束时制作独特的saveall)有一种简单的方法,要求春季在批处理处理过程中暂停特定的AOP尖端,然后在需要时恢复它?
saveAll
我不确定我是否误会了,但是如果我有,请告诉我。
您试图在save
中多次执行save
方法,因此您要在所有method A
save
完成了吗?基于我的理解,我的解决方案如下所示。
save
..
method A
..
@Component
public class BatchProcessingState {
private final AtomicBoolean isBatchMode = new AtomicBoolean(false);
public void enableBatchMode() {
isBatchMode.set(true);
}
public void disableBatchMode() {
isBatchMode.set(false);
}
public boolean isBatchMode() {
return isBatchMode.get();
}
}
rusult:
@Autowired
private BatchProcessingState batchProcessingState;
@Around("xxx")
public Object aroundSaveMethods(ProceedingJoinPoint joinPoint) throws Throwable {
if (batchProcessingState.isBatchMode()) {
return joinPoint.proceed();
}
System.out.println("Intercepts the save method and executes AOP logic...");
Object result = joinPoint.proceed();
System.out.println("The save method completes");
return result;
}