[英]Read number from application.yml file in spring boot
step 1: 第1步:
I wanted to read the configuration file on Spring for minutesو Like the image below: 我想在Spring上阅读配置文件几分钟,就像下面的图片一样:
I used this code: 我使用以下代码:
Environment environment = context.getEnvironment();
log.info("output number:", environment.getProperty("shafagh.job.msg.cron"));
Output: 输出:
output number: 0 0/55 8-13
But this whole line is back, I just want to return a number (0/55) 但是整行都回来了,我只想返回一个数字(0/55)
step 2: 第2步:
convert 0/55 to time or int ? 将0/55转换为时间或整数?
OK, for step 1 , just parse the string. OK,对于第1步 ,只需解析字符串。 There are many possible ways, but i think this one is sufficient: 有很多可能的方法,但是我认为这是足够的:
public static void main(String[] args) {
String cron = "0 0/55 8-13 ? * SAT,SUN,MON,TUE,WED";
String[] parts = cron.split("\\s");
System.out.println("Wanted part is: " + parts[1]); // "0/55"
}
For step 2 , you will need to understand what this expression really means and how you can represent that in Java. 对于步骤2 ,您将需要了解此表达式的真正含义以及如何用Java表示该表达式。 I personally have no idea what you really need from that part (just the frequency? the offset? both of them?) so I cannot answer that part. 我个人不知道您从该部分真正需要什么(只是频率,偏移量还是两个?),所以我无法回答该部分。 Do you know why you want this to be converted into another type than string? 您知道为什么要将其转换为字符串以外的其他类型吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.