是否可以在 Spring 批处理中抛出致命的不可回滚异常?
Is it possible to throw a fatal non-rollbackable exception in Spring Batch?
我尝试了 noSkip(), noRetry(), noRollback()
的所有组合,但我没有实现。
如果我设置没有 noRollback(MyException.class)
的步骤,一旦处理的行抛出异常,该步骤就会失败,但它会回滚所有数据库操作。如果我使用 noRollback(MyException.class)
,那么数据库状态会持续存在,但我没有得到致命错误的日志,并且步骤不是 interrupted/failed。
有什么方法可以直观地处理这个问题吗?这是我试过的最后一个代码
return this.stepBuilderFactory.get(STEP_PROCESS_ROWS)
.faultTolerant()
.noSkip(UnexpectedJobExecutionException.class)
.noRetry(UnexpectedJobExecutionException.class)
.noRollback(UnexpectedJobExecutionException.class)
.reader(myReader)
.processor(myProcessor)
.writer(myWriter)
.build();
Is it possible to throw a fatal non-rollbackable exception in Spring Batch?
是的,像您一样使用 FaultTolerantStepBuilder#noRollback。 noSkip
和 noRetry
有不同的含义。
If I set the step without noRollback(MyException.class), the step fails as soon as the processed row throws the exception, but it rollbacks all db actions.
这是默认行为。如果出现异常,事务回滚,步骤失败。
If I use noRollback(MyException.class), then the db state is persisted, but I get no log of the fatal error and step is not interrupted/failed.
这里没有什么奇怪的(我希望):由于事务没有回滚,状态被持久化并且步骤继续。确保将日志级别设置为 debug
以获取所有详细信息。
我尝试了 noSkip(), noRetry(), noRollback()
的所有组合,但我没有实现。
如果我设置没有 noRollback(MyException.class)
的步骤,一旦处理的行抛出异常,该步骤就会失败,但它会回滚所有数据库操作。如果我使用 noRollback(MyException.class)
,那么数据库状态会持续存在,但我没有得到致命错误的日志,并且步骤不是 interrupted/failed。
有什么方法可以直观地处理这个问题吗?这是我试过的最后一个代码
return this.stepBuilderFactory.get(STEP_PROCESS_ROWS)
.faultTolerant()
.noSkip(UnexpectedJobExecutionException.class)
.noRetry(UnexpectedJobExecutionException.class)
.noRollback(UnexpectedJobExecutionException.class)
.reader(myReader)
.processor(myProcessor)
.writer(myWriter)
.build();
Is it possible to throw a fatal non-rollbackable exception in Spring Batch?
是的,像您一样使用 FaultTolerantStepBuilder#noRollback。 noSkip
和 noRetry
有不同的含义。
If I set the step without noRollback(MyException.class), the step fails as soon as the processed row throws the exception, but it rollbacks all db actions.
这是默认行为。如果出现异常,事务回滚,步骤失败。
If I use noRollback(MyException.class), then the db state is persisted, but I get no log of the fatal error and step is not interrupted/failed.
这里没有什么奇怪的(我希望):由于事务没有回滚,状态被持久化并且步骤继续。确保将日志级别设置为 debug
以获取所有详细信息。