访问注释中的属性值 [英] Accessing property values in Annotations

查看:27
本文介绍了访问注释中的属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的注释中访问一个属性值,作为一个属性的值.

I want to access a property value in my annotation, as an attribute's value.

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

For ex. in my property file I have an entry expression: 3/10 * * * * ?.

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

In my Scheduler class I use annotation @Scheduled (cron = "**VALUE**"). I want to read this value from the properties file corresponding to the expression key.

尝试使用 @Value 执行此操作,但它返回一种无法转换为 StringValue 类型.

Tried doing this with @Value, but it returns a type of Value which cannot be converted to String.

推荐答案

从 spring 3.0.1 开始你可以这样做@Scheduled(cron = "${rates.refresh.cron}")

From spring 3.0.1 you can do it like this @Scheduled(cron = "${rates.refresh.cron}")

参考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 中查看 Mark 的评论

However, you cannot do this for fixDelay and fixRate due to type casting problem (fixDelay expects value in long, while annotation return String only). Check Mark's comments in https://jira.springsource.org/browse/SPR-6670

这篇关于访问注释中的属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆