yml 使用
一行
address: {province: 山东, city: 济南}
数组
hobbyList: [游泳, 跑步]
一般地,yml的配置供给web模块,其他模块想使用怎么办?
先使用 @ConfigurationProperties放入容器;然后在进行启动的时候放入全局变量;
使用Jackson处理yaml文件
【one】读取yml为Bean,放入spring容器

【two】启动的时候,放入全局

@Bean
public CommandLineRunner running(ApplicationContext context) {
return args -> {
log.info("now start to set variable");
SimulatorConfiguration bean = context.getBean(SimulatorConfiguration.class);
System.setProperty("imei",bean.getImei());
System.setProperty("version_808",bean.getVersion());
};
}
如果您觉得我的付出对您有帮助,还请关注+点赞哦
本文探讨了YML配置文件的使用方法,特别是在Spring框架中如何将YML配置注入到Bean中并设置为全局变量。介绍了通过@ConfigurationProperties注解和CommandLineRunner接口实现这一过程的技术细节。
2769

被折叠的 条评论
为什么被折叠?



