TheRock3t
TheRock3t

Reputation: 638

Inject bean property in @Scheduled annotation

In my class I have an @Autowired bean which holds a cron expression in one of it's attributes.

In the same class I have a @Scheduled method, and I wish to set the cron expression to the bean's property.

I tried this already and it doesn't work

@Scheduled(cron = "#{propertyBean.cronExpression}")

Any ideas?

Thank you.

Upvotes: 1

Views: 1096

Answers (1)

Avery Sturzl
Avery Sturzl

Reputation: 92

This annotation worked for me:

@Scheduled(cron = "${property.with.cron}")

With this in our spring profile/application.properties:

property.with.cron=*/10 * * * * *

We're using spring boot just fyi

Upvotes: 1

Related Questions