在Annotations中访问属性值 [英] Accessing property values in Annotations

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

问题描述

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

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

对于ex。在我的属性文件中,我有一个条目表达式: 3/10 * * * *?

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

在我的调度程序中class I使用注释 @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 执行此操作,但它返回一种 Value ,它无法转换为 String

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

推荐答案

从春季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为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

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

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