简体   繁体   English

如何从 application.yml 中读取 Long 数字

[英]How to read a Long number from application.yml

The application.yml file has a Long type setting: application.yml 文件有一个 Long 类型设置:

producer.init-delay: 15000

It is used in this method:它用于此方法:

@Scheduled(fixedRate = 25000, initialDelay = "#{new Long('${producer.init-delay}')}")
public produce() {}

Take an example from the question: Spring @Value TypeMismatchException:...以问题为例: Spring @Value TypeMismatchException:...

But I have this code gives an error:但是我有这个代码给出了一个错误:

Incompatible types. Found: 'java.lang.String', required: 'long'

According to the javadoc of the @Scheduled , initialDelay must be of type long and you have it as String .根据@ScheduledjavadocinitialDelay必须是long类型,并且您将其作为String

Every long argument in @Scheduled has a string alternative. @Scheduled中的每个long参数都有一个字符串替代项。 Use them:使用它们:

@Scheduled(fixedRate = 25000, initialDelayString = "${producer.init-delay}")
public produce() {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM