我想访问注释中的属性值,作为属性的值。
对于前。在我的属性文件中,我有一个条目表达式:3/10 * * * * ?
.
在我的 Scheduler 类中,我使用注释@Scheduled (cron = "**VALUE**")
。我想从表达式键对应的属性文件中读取这个值。
尝试这样做@Value
,但它返回一个类型Value
不能转换为String
.
从 spring 3.0.1 开始你可以这样做
@Scheduled(cron = "${rates.refresh.cron}")
参考http://forum.springsource.org/showthread.php?83053-Feature-Scheduled-with-Value-cron-expression http://forum.springsource.org/showthread.php?83053-Feature-Scheduled-with-Value-cron-expression
但是,由于类型转换问题,您无法对 fixDelay 和 fixRate 执行此操作(fixDelay 需要 long 值,而注释仅返回 String)。检查马克的评论https://jira.springsource.org/browse/SPR-6670 https://jira.springsource.org/browse/SPR-6670
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)