Spring INT property for annotation int parameter for spring application?

Viewed 234

I have spring-boot application. application.xml and some annotated methods. In case string properties from application.xml is OK. For example:

@KafkaListener(id = "${app.kafka.group}", topics = {"${app.kafka.topic}"}, containerFactory = "singleFactoryCap", autoStartup = "true")
    public void consume(Event event) throws ParseException { ...

But how to put INTEGER property from application.xml into an annotation parameter of method?

@Scheduled(initialDelay = ???"${app.config.initialDelay:5000}"???, fixedDelay = ???"${app.config.fixedDelay:5000}"???)
    public void loadEvents() {
1 Answers

The @Scheduled annotation takes long properties initialDelay, fixedRate and fixedDelay if you want to hard-code the values but the annotation also provides the properties initialDelayString, fixedRateString and fixedDelayString that you can use as an alternative if you want to configure the behaviour using external configuration properties.

Related