【发布时间】:2020-01-17 05:51:43
【问题描述】:
我可以从属性文件实体的键值存储在变量(contants 类)中的属性文件中获取值吗?
结构如下: 属性文件
x.y.z=123
常量文件
public static final String abc = "x.y.z";
服务类
@Value(${"getConstant("abc").getValueOfProperty()})
public String resource;
【问题讨论】:
-
如果它是一个充满静态常量的类,当然。
-
这里我不想只从常量类中读取值。价值转移在这里发生了两次。
-
只要
String变量是final的,就可以在@Value注解中使用。 -
请提供一些示例代码。
-
结构类似于:属性文件--- x.y.z=123 常量文件== public static string abc = "x.y.z" 服务类 --- @Value(${"getConstant("abc") .getValueOfProperty()})