spring boot 除@Value 外,如何获得配置文件中的内容

配置文件位置:

spring boot 除@Value 外,如何获得配置文件中的内容

读取文件中的内容代码:

Resource resource = new ClassPathResource("/my-application.properties");
Properties properties = PropertiesLoaderUtils.loadProperties(resource);
String name = (String) properties.get("myname"); //  myname 为my-application.properties中的键值
System.out.println("输出值。。"+ name);