访问注解中的属性值

问题描述:

我想在我的注释中访问属性值,作为属性的值。访问注解中的属性值

例如,在我的财产文件中,我有一个条目表达式:3/10 * * * * ?

在我的调度程序类中,我使用注释@Scheduled (cron = "**VALUE**")。我想从对应于表达式键的属性文件中读取这个值。

试图用@Value这样做,但它返回一种类型的Value,它不能转换为String

+0

假设你正在使用spring,请看看这个线程:http://forum.springsource.org/showthread.php?83053-Feature-Scheduled-with-Value-cron-expression/ – 2011-12-12 06:14:53

您可以尝试使用APT(注释处理工具)将注释中的值替换为属性文件中的值。

从春天3.0.1你可以做这样的 @Scheduled(的cron = “$ {} rates.refresh.cron”)

参考 http://forum.springsource.org/showthread.php?83053-Feature-Scheduled-with-Value-cron-expression

但是,你不能这样做for fixDelay和fixRate由于类型转换问题(fixDelay需要长整型值,而annotation仅返回String)。检查标记的意见https://jira.springsource.org/browse/SPR-6670