How to Use ControllerAdvice for Exception Handling in Spring Batch Application?

27 views Asked by At

I am relatively new to Spring Boot and Spring Batch, and I'm currently working on a project where I need to implement exception handling. However, I'm facing difficulties in getting ControllerAdvice to work properly in my Spring Batch application.

My application primarily communicates with an Oracle database and does not involve any API calls or mapping annotations like @RequestMapping. Despite this, I want to utilize ControllerAdvice for handling exceptions effectively.

My concern is whether ControllerAdvice will function in my scenario where there are no explicit API mappings. If not, I would appreciate guidance on how to make it work. Currently, I'm throwing SQLExceptions, but they aren't being caught by ControllerAdvice.

Could someone provide insights or a solution on how to effectively implement exception handling using ControllerAdvice in a Spring Batch application without API mapping annotations?

My Tasklet:

@Override
public RepeatStatus execute(StepContribution contribution. ChunkContext chunkContext) throws SQLExecption{
  throw new SQLException("Trying");
}

My global exception handler:

@ExceptionHandler(Value = SQLException.call)
public void handleSqlException(String message){
   logger.error("An error occured")
}
0

There are 0 answers