-1

I build simply web application with Spring Boot but I need to create Sheduled task in Application that I create Cron job but dont working. That is my code for task:

@Component
public class CronService {
    @Autowired
    private XmlDeserializer xmlDeserializer;

    @Autowired
    private CurrencyRepository currencyRepository;

    @Scheduled(cron = "0 12 0 * * *", zone = "Europe/Sofia")
    public void saveData() throws IOException, SAXException, ParserConfigurationException {
...
}

And this is my Аpplication.java code for Spring boot:

@SpringBootApplication
@EnableScheduling
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Ivan Ivanov
  • 193
  • 3
  • 12
  • What is not working? Does the app compiles/starts at all? Is there an error either runtime or compilation one that leads you to the fact something is not working? – dbl Sep 26 '18 at 15:03
  • Welcome to Stack Overflow! When you say something isn't working, please tell us what exactly isn't working. e.g. you get no callbacks at all, or perhaps your code doesn't compile. This lack of complete information leads to frustration and probably downvotes. – Andy Brown Sep 26 '18 at 16:17
  • Task not exected :( – Ivan Ivanov Sep 27 '18 at 08:43

1 Answers1

1

I assume you are in need of the CRON to run 5 times per hour, respectively at xx:00, xx:12, xx:24, xx:36, xx:48... The correct syntax will be : 0 0/12 * * * ?. And the other assumption will be running the cron once per hour at exactly xx:12 then you should use: 0 12 * * * ?.

I will advice you to use an external tool that will help you out with creating cron expressions like cronmaker.

dbl
  • 1,109
  • 9
  • 17