Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Quarkus: Inject config properties into annotation parameters

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}").

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading