0

I have to schedule a method with @Scheduled Annotation which only takes a constant variable as a parameter. But I want this constant to be initialized from a databag instead of hard coding it. Is there a way to do it?

I can you timer and it works but I want to know if this is possible.I have tried initializing the variable in PostConstruct annotation but it didn't work either as final variables has to be initialized at declaration

   static final int t ;
   @Scheduled(fixedDelay = t)
   public void pushToSearchPeriodic(){
       publishSearchMessagesAndFlush();
   }

need to avoid hard code variable t.

Aman Kumar Sinha
  • 407
  • 6
  • 17
  • No: annotations are compile-time beings and you can't feed a runtime value into one – giorgiga Apr 17 '19 at 07:12
  • I figured that. I needed to know if its possible to initialize a final variable from a value from databag or database – Aman Kumar Sinha Apr 17 '19 at 07:28
  • Yes (and also, you don't want to do that), but then you can't use that value in an annotation because it's no longer a "constant expression". – giorgiga Apr 17 '19 at 07:33

0 Answers0