在配置文件中读字段:
@PropertySource(value = "classpath:xxx.properties",encoding = "utf-8")//在springboot中可以不用添加
@Value("${key}")
private String testKey;
在配置文件中读Map:
@Value("#{${xxxxx}}")
private HashMap<String, String> testMap;
xxxxx={ key:value }
本文介绍如何在SpringBoot应用中从配置文件读取字段和Map类型的配置信息。通过使用@PropertySource和@Value注解实现。适用于需要动态加载配置的应用场景。
在配置文件中读字段:
@PropertySource(value = "classpath:xxx.properties",encoding = "utf-8")//在springboot中可以不用添加
@Value("${key}")
private String testKey;
在配置文件中读Map:
@Value("#{${xxxxx}}")
private HashMap<String, String> testMap;
xxxxx={ key:value }
443

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