一般情况下,java springboot读取yml文件的方法
1 写yml文件
2 写一个配置相关的类
3 启动类上加标签
代码如下
复制代码
1
2
3
4
5
6
7
8文件 XXX.yml 只是举例 与实际项目无关 index: indexFileRootPath: C:UsersAdministratorDesktopdata indexFileName: videoInfo.txt # 表示定时任务的字符串 cronString: 0 45 3-23 * * ? indexStartDay: 20181211
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24@Data @ConfigurationProperties("index") public class VideoIndexProperties { /** * 首页文件根路径 */ private String indexFileRootPath; /** * 存储视频首页信息的文件名 */ private String indexFileName; /** * 表示定时任务的字符串 */ private String cronString; /** * 没有任务时开始入库的日期 */ private int indexStartDay; }
复制代码
1
2
3
4
5
6
7
8
9
10/** * 启动类 * @author szb */ @SpringBootApplication @EnableConfigurationProperties(VideoIndexProperties.class) @EnableScheduling public class TestApplication { public static void main
最后
以上就是忧虑战斗机最近收集整理的关于java,springboot 在注解中读取yml文件的变量的方法的全部内容,更多相关java,springboot内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复