【问题标题】:Inject bean property in @Scheduled annotation在 @Scheduled 注解中注入 bean 属性
【发布时间】:2016-12-26 09:47:01
【问题描述】:

在我的课堂上,我有一个 @Autowired bean,它在其中一个属性中包含一个 cron 表达式。

在同一个类中,我有一个 @Scheduled 方法,我希望将 cron 表达式设置为 bean 的属性。

我试过了,还是不行

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

有什么想法吗?

谢谢。

【问题讨论】:

标签: java spring annotations scheduled-tasks


【解决方案1】:

这个注释对我有用:

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

在我们的 spring profile/application.properties 中有这个:

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

我们正在使用弹簧靴,仅供参考

【讨论】:

    猜你喜欢
    • 2012-08-06
    • 2011-06-05
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多