简体   繁体   English

在Spring Boot中从application.yml文件读取编号

[英]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.

相关问题 如何从 spring-boot 应用程序中的 application.yml 文件中读取属性 - How to read properties from application.yml file in spring-boot application 从 spring-boot 中的 application.yml 文件中获取 cron - Get cron from application.yml file in spring-boot 无法从 Java Spring Boot 项目的 application.yml 文件中读取用户定义的类列表 - Unable to read list of user defined class from application.yml file in a Java Spring Boot project Docker 图像无法读取 Spring 引导应用程序上的 application.yml 文件 - Docker image can't read application.yml file on Spring Boot Application spring boot中application.yml是按什么顺序读取的? - In what order are application.yml read in spring boot? Spring Boot-无法读取Yaml属性文件application.yml - spring boot- unable to read yaml properties file application.yml Spring Boot - 从 application.yml 和 application.properties 注入 - Spring Boot - inject from application.yml and application.properties 如何使用Spring Boot从application.yml读取变量并在Kotlin测试中使用它 - How to read variable from application.yml with spring boot and use it in kotlin test Flyway-maven-plugin如何从Spring Boot application.yml中读取设置 - Flyway-maven-plugin how to read the settings from spring boot application.yml Spring Boot - 无法从实例化对象中读取 application.yml 值 - Spring Boot - Cannot read application.yml values from instantiated object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM