How to customize the exception handling for @Scheduled
annotation from spring ?
I have Cron jobs which will be triggered in the server (Tomcat 6) and when any exceptions occur I need to do some handling.
- Spring version 3.2
- Tomcat Server 6
How to customize the exception handling for @Scheduled
annotation from spring ?
I have Cron jobs which will be triggered in the server (Tomcat 6) and when any exceptions occur I need to do some handling.
If you want to use Java Config you will need to create configuration implementing SchedulingConfigurer
You can modify error handler for your needs. Here I only log a message.
Don't forget to call taskScheduler.initialize();. Without it you'll get:
You could implement and register an
ErrorHandler
for theThreadPoolTaskScheduler
that is used for your scheduling annotations.Why not wrap your business logic and do a simple try catch in your @schedule method. Then you can log or take whatever action is necessary for failure cases.