Java 我是否可以在@Value注释中传递变量以读取属性文件,该属性文件的键存储在字符串变量中?
我是否可以从属性文件中获取值,其中属性文件实体的键的值存储在变量(contants类)中 结构如下: 属性文件Java 我是否可以在@Value注释中传递变量以读取属性文件,该属性文件的键存储在字符串变量中?,java,spring,Java,Spring,我是否可以从属性文件中获取值,其中属性文件实体的键的值存储在变量(contants类)中 结构如下: 属性文件 x.y.z=123 常量文件 public static final String abc = "x.y.z"; 服务类 @Value(${"getConstant("abc").getValueOfProperty()}) public String resource; 我想,我们可以这样做 private final String VALUE_STRING = "$
x.y.z=123
常量文件
public static final String abc = "x.y.z";
服务类
@Value(${"getConstant("abc").getValueOfProperty()})
public String resource;
我想,我们可以这样做
private final String VALUE_STRING = "${external.value:default}";
@Value(VALUE_STRING)
private String value;
如果它是一个充满静态常量的类,当然。在这里,我不想只读取常量类的值。值的传输在这里发生了两次。只要
字符串
变量是最终变量,就可以在@Value
注释中使用它。请提供一些示例代码。结构类似于:properties file--x.y.z=123 Constant file==public static String abc=“x.y.z”服务类类似于--@Value(${“getConstant”)(“abc”).getValueOfProperty()})