简体   繁体   English

在@Scheduled注释中注入bean属性

[英]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. 在我的课堂上,我有一个@Autowired bean,它在其中一个@Autowired中包含一个cron表达式。

In the same class I have a @Scheduled method, and I wish to set the cron expression to the bean's property. 在同一个类中,我有一个@Scheduled方法,我希望将cron表达式设置为bean的属性。

I tried this already and it doesn't work 我已经尝试了这个,它不起作用

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

Any ideas? 有任何想法吗?

Thank you. 谢谢。

This annotation worked for me: 这个注释对我有用:

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

With this in our spring profile/application.properties: 在我们的spring profile / application.properties中有这个:

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

We're using spring boot just fyi 我们使用弹簧靴只是fyi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM