-1

I have this TaskSchedule running in a SpringBoot application

@Scheduled(cron = "0 0/10 * * * ?")
    public void hotelTime() throws IOException {



            LOG.info("updating all hotels at " + new Date());
            List<Hotel> currenciesInfo = hotelService.getAllHotelsInfo();
            for (Hotel hotelInfo : hotelsInfo) {
                hotelPriceService.updateHotelPrice (hotelInfo, usdRate);
            }
            LOG.info("updated at " + new Date());

            currencyPriceService.deletePriceOlderThan1Month ();

    }

But I see this error in the Log file

 2018-03-25 19:44  [pool-2-thread-1] ERROR o.s.s.s.TaskUtils$LoggingErrorHandler.handleError(95) - Unexpected error occurred in scheduled task.
java.lang.NullPointerException: null
Salvador Borés
  • 165
  • 1
  • 3
  • 9
  • I don't think it has anything to do with Spring and Scheduling. Check you class dependencies. Check the stack trace it should also point to the location of null pointer, also check if `hotelService` or `hotelPriceService` is assigned correctly. – Amit Phaltankar Mar 25 '18 at 20:12
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – 1615903 Mar 26 '18 at 05:48

1 Answers1

1

This error has nothing to do with Scheduler i-e @Scheduled annotation. Scheduler is running fine but "LOG" object is not initiated properly, LOG object is returning null. Make sure you initiated LOG object as :

private static final Logger LOG = LoggerFactory.getLogger(<Your Class Name>.class);
Rezwan
  • 1,203
  • 1
  • 7
  • 22