java - 参考 @Scheduled by SpEL 中的 bean.property
问题描述
我将在@Scheduled 中动态设置“fixedRate”值。
为此,我正在尝试使用 SpEL 能力,如下所示:
@AllArgsConstructor
public class ContentSender {
@Scheduled(fixedRateString = "#{OuterProperties.rateForMessageReading}")
public void contentModelMessageSource() throws IOException {
}
}
具有目标属性的类:
@Getter
@Setter
@ConfigurationProperties("app")
public class OuterProperties {
private static final long WAITING_INTERVAL = 100;
private long rateForMessageReading;
}
结果在部署阶段我收到:
SpelEvaluationException: EL1008E: Property or field 'outerProperties' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
我究竟做错了什么?
解决方案
问题是我只使用@ConfigurationProperties。当我添加@Configuration 问题就消失了。
@Getter
@Setter
@Configuration
@ConfigurationProperties("app")
public class OuterProperties {
private static final long WAITING_INTERVAL = 100;
private long rateForMessageReading;
}
推荐阅读
- ios - 如何在任何情况下快速更改导航栏按钮项目的颜色?
- amazon-web-services - 使用 AWS CLI 测试 Amazon SageMaker 模型终端节点时,base64 无效:"{"instances": [{"in0":[863],"in1":[882]}]}"
- python - Django 3.* Python 3.* - 在数据库方法中节省空间
- javascript - 如何在 Tampermonkey 脚本上添加下一个/上一个按钮分页?
- python - 使用python的快速排序算法
- javascript - 如何根据用户类型更改 VueJS 中的背景
- spring - 为什么我的 H2 数据库 Spring 配置不起作用?
- tensorflow - 当验证数据的准确性增加但损失也在增加时该怎么办?
- c - Makefile 我可以只执行一次配置吗?
- python - Python:如何以编程方式停止节俭服务器?