我有这个spring-cloud-config客户端类,我可以使用@Value注释来访问各个属性.但是,我有兴趣知道如何从属性文件中读取所有属性值,而不将每个属性的键绑定到@Value注释.基本上我的想法是,我想从属性文件中读取所有属性值,甚至不知道文件中定义的属性.知道我怎么能这样做吗?
@EnableAutoConfiguration
@ComponentScan
@RestController
@RefreshScope
public class ConfigDemoClientApplication
{
@Value("${special}")
String special;
@RequestMapping("/restaurant")
public String hello()
{
return "Hello " + special;
}
public static void main(String[] args) {
SpringApplication.run(ConfigDemoClientApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
示例属性文件
special: bargain!
amount: 200
city: New York
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我想读取所有3个属性,而不是在我的类中为每个属性定义@Value注释.那可能吗?
谢谢你的帮助.