Spring 弹簧将特定属性加载到属性对象中

Spring 弹簧将特定属性加载到属性对象中,spring,properties,Spring,Properties,Myapplication.properties包含以下属性: db.username = ... db.password = ... db.timeout = ... rest.client.username = ... rest.client.password = ... rest.client.timeout = ... 我只想将rest客户端的属性加载到配置中 @Configuration public class Config { .... private Properties

My
application.properties
包含以下属性:

db.username = ...
db.password = ...
db.timeout = ...

rest.client.username = ...
rest.client.password = ...
rest.client.timeout = ...
我只想将rest客户端的属性加载到配置中

@Configuration
public class Config {

....

private Properties restProperties; // << here should go 3 properties with prefix rest.client

}
@配置
公共类配置{
....

私有属性restProperties;//如果将所有
rest.client
属性移动到它们自己的属性文件中(例如
restclient.Properties
),则可以使用:

或者,您可以使用,如图所示,但它不是
属性
对象,而是您自己定义的对象

另外,我觉得这可能值得一提,您可以添加

@Autowired
private Environment env;
并使用访问任何属性

env.getProperty("your.property.here")
env.getProperty("your.property.here")