Quarkus: Inject config properties into annotation parameters

836 views Asked by At

Currently, we use the @Scheduled annotation from quarkus-scheduler to periodically execute a method:

@Scheduled(every = "10s")
void sync() {
  ...
}

I would like to make the interval configurable in application.properties. Is there a way to inject a configuration property into the value of the every parameter? E.g. something like @Scheduled(every = "${sync.interval}").

1

There are 1 answers

0
JCompetence On BEST ANSWER

The every attribute supports Property Expressions including default values and nested Property Expressions.

(Note that "{property.path}" style expressions are still supported but don’t offer the full functionality of Property Expressions.)

Interval Config Property Example

@Scheduled(every = "${myMethod.every.expr}")
void myMethod() { }

https://quarkus.io/guides/config-reference#property-expressions

https://quarkus.io/guides/scheduler-reference#intervals