I am working on a Spring project. I want to use scheduler in it and want to schedule it on a variable date. This date has to be taken from database. Is it possible to fetch data from database before server is getting started?
            Asked
            
        
        
            Active
            
        
            Viewed 142 times
        
    0
            
            
        - 
                    Maybe you your answer is here: https://stackoverflow.com/a/49994397/11733759 – lczapski Nov 26 '19 at 12:13
- 
                    Thanks for your answer, but I am not using Spring scheduler instead I am using Quartz API for scheduling. – Mint123 Nov 26 '19 at 12:37
- 
                    Can you post your code that uses of Quartz API for scheduling? – lczapski Nov 26 '19 at 13:12
1 Answers
0
            
            
        Two solutions come to my mind:
- @PostConstructannotated method of some- @Component:- @Component public class MyBean { @PostConstruct public void init() { // Blocking DB call could go here } }
- Application Events. For the - ApplicationReadyEvent:- @Component public class ApplicationReadyEventListener implements ApplicationListener<ApplicationReadyEvent> { @Override public void onApplicationEvent(ApplicationReadyEvent event) { // DB call could go here // // Notice that if this is a web services application, it // would potentially be serving requests while this method // is being executed } }
 
    
    
        gears
        
- 690
- 3
- 6
