我想使用 @PropertySource 注释设置动态属性源值。谁能告诉我如何实现这一目标?对于下面我动态传递属性文件名。
@Configuration
@PropertySource("classpath:message.properties")
public abstract class AbstractCommonAMQPConfiguration {
@Value("${cust.name}")
private String custName;
@Value("${cust.id}")
private String custId;
}
Run Code Online (Sandbox Code Playgroud)
我不确定如何做到这一点,@PropertySource但您可以PropertySourcesPlaceholderConfigurer以编程方式定义:
private int some_value = 1;
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
propertySourcesPlaceholderConfigurer.setLocation(new ClassPathResource("test" + some_value + ".properties"));
return propertySourcesPlaceholderConfigurer;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6524 次 |
| 最近记录: |